
Richie
24.04.2017
23:23:44
wow

Luckydonald
24.04.2017
23:25:15
How can I use the same in-memory SQLite database in two different .bind(...) statements?

Google

Janis
25.04.2017
16:12:26
Not directly related to Pony ORM, but what's the best way to generate a new database and create a user for this database?

Alexey
25.04.2017
16:16:50

Janis
25.04.2017
16:16:59
mysql

Alexey
25.04.2017
16:17:33
https://www.mysql.com/products/workbench/
or console

Janis
25.04.2017
16:20:51
Since I mean using python to generate this user and database for user I would need to use console right?

Alexey
25.04.2017
16:23:40
do you want to create it one time, or you want to automate this process? it is not clear from your question

Janis
25.04.2017
16:33:58
I would need to call this code from my application. It's for an API endpoint. Each time a new user orders a server a new database access (user) and a database needs to be created for this user.
Api endpoint itself is done, now I just wonder how to create database and user for this database

Alexey
25.04.2017
16:39:03
http://stackoverflow.com/questions/33768386/create-a-mysql-database-in-python
http://stackoverflow.com/questions/8932261/create-mysqldb-database-using-python-script

Janis
25.04.2017
16:40:18
big thanks

Luckydonald
25.04.2017
17:37:48
Ah, probably using
'file::memory:?cache=shared' as filename
http://stackoverflow.com/a/15720872/3423324

Google

Luckydonald
25.04.2017
17:43:00
Seems you can even give them a name:
file:filename?mode=memory&cache=shared
file:foobar?mode=memory&cache=shared
https://www.sqlite.org/inmemorydb.html

Alexey
25.04.2017
17:46:53
Don't think so
http://stackoverflow.com/questions/3315046/sharing-a-memory-database-between-different-threads-in-python-using-sqlite3-pa
Wait, read the second answer

Luckydonald
25.04.2017
18:15:17
But PonyORM doesn't handle the file: protocol, it seems.
I logged it at https://github.com/ponyorm/pony/issues/260
.

Alexey
25.04.2017
18:16:07
In the same thread you can call generate_mapping() only once

Luckydonald
25.04.2017
18:16:46

Alexey
25.04.2017
18:16:50
Why would you need this?


Luckydonald
25.04.2017
18:17:58
The example code of pony_up.
https://github.com/luckydonald/pony_up
Permanent link to the luckydonald/pony_up project you mentioned. (?)
Okey, trying sqlite file now...
But I get the following error, and have no clue where it comes from.
Traceback (most recent call last):
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/dbapiprovider.py", line 48, in wrap_dbapi_exceptions
try: return func(provider, *args, **kwargs)
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/dbapiprovider.py", line 239, in execute
if arguments is None: cursor.execute(sql)
sqlite3.OperationalError: near "(": syntax error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/Python/pony_up/example/example.py", line 17, in <module>
db = migrate(bind_to_database, folder_path=migrations_folder, python_import=python_import)
File "/path/to/Python/pony_up/pony_up/do_update.py", line 191, in do_all_migrations
bind_database_function(db)
File "/path/to/Python/pony_up/example/example.py", line 7, in bind_to_database
db.generate_mapping(create_tables=True)
File "<string>", line 2, in generate_mapping
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/utils/utils.py", line 58, in cut_traceback
return func(*args, **kwargs)
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/core.py", line 882, in generate_mapping
if create_tables: database.create_tables(check_tables)
File "<string>", line 2, in create_tables
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/utils/utils.py", line 58, in cut_traceback
return func(*args, **kwargs)
File "<string>", line 2, in create_tables
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/core.py", line 413, in new_func
try: return func(*args, **kwargs)
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/core.py", line 940, in create_tables
database.schema.create_tables(database.provider, connection)
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/dbschema.py", line 56, in create_tables
if name is None: db_object.create(provider, connection)
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/dbschema.py", line 84, in create
provider.execute(cursor, sql)
File "<string>", line 2, in execute
File "/path/to/Python/pony_up/virtualenv3.6.0.venv/lib/python3.6/site-packages/pony/orm/dbapiprovider.py", line 53, in wrap_dbapi_exceptions
except dbapi_module.OperationalError as e: raise OperationalError(e)
pony.orm.dbapiprovider.OperationalError: near "(": syntax error
Wow, this is a lot of text ?
From the changelog (https://docs.ponyorm.com/upgrade_pony.html?highlight=structure#upgrade-pony-to-version-0-8)
"To move to a new version of Pony's we need to rename tables, and rename foreign_keys and index, because they contain the table name."
"Чтобы перейти на новую версию Пони нам нужно переименовать таблицы и также переименовать foreign_keys и index, потому что они содержат в себе имя таблицы."
Does that mean, I can't rename my Table later?
Or will official migrations be able to handle that?
Also is there somewhere to find about this official migrations?
Is that development done in the orm branch=


Amit Kumar
25.04.2017
21:20:31
Hey everyone,
I'm Amit from India
How can I use PonyORM to translate natural language to sql query?

Rozen
25.04.2017
21:22:11
wtf

Google

Amit Kumar
25.04.2017
21:22:30

Rozen
25.04.2017
21:23:49
i'm not on thopic but that sounds like you should get your own code to proceess the text and have some logic plasmated into code that would do PonyORM queries

Amit Kumar
25.04.2017
21:24:58

Rozen
25.04.2017
21:25:34
i repeat, i'm not on thopic maybe you can do something more straightforward

Amit Kumar
25.04.2017
21:25:49
Someone is actually did the same in python using nltk but I unable to build it on my local system


Luckydonald
25.04.2017
21:31:00
For reference, this is how I will block 2 processes to concourently try to do database migrations:
con = psycopg2.connect(host=POSTGRES_HOST, user=POSTGRES_USER, password=POSTGRES_PASSWORD, database=POSTGRES_DB)
cur = con.cursor()
cur.execute("SELECT pg_try_advisory_lock(85,80);") # update lock (ascii: UP)
res = cur.fetchone()
if not isinstance(res[0], bool) or not res[0]:
# True = success
# Fail => false or no bool
raise ValueError("Currently already upgrading. (Advisory Lock 85,80)")
# end if
db = migrate(...)
cur.execute("SELECT pg_advisory_unlock(85,80);") # update lock (ascii: UP)
res = cur.fetchone()
if not isinstance(res[0], bool) or not res[0]:
# True = success
# Fail => false or no bool
raise ValueError("Could not release update lock, lock was not held (Advisory Lock 85,80)")
# end if`
Following this article:
https://hashrocket.com/blog/posts/advisory-locks-in-postgres
For reference, this is how I will block 2 processes to concourently try to do database migrations:
con = psycopg2.connect(host=POSTGRES_HOST, user=POSTGRES_USER, password=POSTGRES_PASSWORD, database=POSTGRES_DB)
cur = con.cursor()
cur.execute("SELECT pg_try_advisory_lock(85,80);") # update lock (ascii: UP)
res = cur.fetchone()
if not isinstance(res[0], bool) or not res[0]:
# True = success
# Fail => false or no bool
raise ValueError("Currently already upgrading. (Advisory Lock 85,80)")
# end if
db = migrate(...)
cur.execute("SELECT pg_advisory_unlock(85,80);") # update lock (ascii: UP)
res = cur.fetchone()
if not isinstance(res[0], bool) or not res[0]:
# True = success
# Fail => false or no bool
raise ValueError("Could not release update lock, lock was not held (Advisory Lock 85,80)")
# end if`
Following this article:
https://hashrocket.com/blog/posts/advisory-locks-in-postgres
However this only works in postgres.
How do you guys will do it?
Also wrote about it here:
https://github.com/luckydonald/pony_up#my-application-with-the-migration-will-run-multible-times-at-the-same-time
Permanent link to the luckydonald/pony_up project you mentioned. (?)


Henri
28.04.2017
20:04:22
Hey!
I wanted to ask if there're still plans to integrate GraphQL in Ponyorm.
I also wantedt to introduce [more.pony](https://github.com/morepath/more.pony), which integrates PonyORM with [Morepath](http://morepath.readthedocs.io).
Released that last week.

Janis
29.04.2017
16:02:57
let's say my table looks like this: servers: id|slots|...
Is there some easys way to sum the slots of all servers?
I already tried sth. like this
used_slots = db.Servers.sum(slots)
#got it :)
How to insert a value as type "NULL" using PONY?
if is_local:
ip_database = "NULL"
else:
ip_database = ip

Google

Janis
29.04.2017
18:43:54
This doesn't work, since the ip field in database is "varchar". So how to do this?

stsouko
29.04.2017
18:47:15
atrr=None

Janis
29.04.2017
18:50:07
How should I create my attribute inside the model then?
ip = (str, 32, nullable = True, default = None)?
got it

stsouko
29.04.2017
18:53:10
ip = Optional(str)

Janis
29.04.2017
18:54:07
ip = Optional(str, 32, nullable = True, default = None)
I use this atm. Using this PONY will handle all the stuff, using your solution will make the mysql server set the default value ;)

stsouko
29.04.2017
18:54:52
without default = None

Janis
29.04.2017
18:55:10
Why without?

stsouko
29.04.2017
18:56:27
Optional atrrs if not set is None

Janis
29.04.2017
18:59:42
So you mean, for all kind of optional attributes if NO value is net (None) then this will lead to type NULL in database automatic?

stsouko
29.04.2017
19:06:51
Optional(str, 32, nullable=True)

Micaiah
01.05.2017
12:55:20
Why doesn't Pony use interactive mode in iPython?
Oh nevermind, its when you use any form of python -i models.py

Alexey
02.05.2017
02:27:11

Henri
02.05.2017
06:41:12
Great! I think about GraphQL integration in Morepath and if PonyORM would support GraphQL this would be a good starting point. ☺

Kristian
04.05.2017
10:56:49
Hi folks,
thanks a lot for this awesome ORM, it's really fun working with it!
I would like to be able to store decimal.Decimal in JSON Fields of pony entities. As the default JSON Encoder (json.JSONEncoder) does not support Decimal, I would like to be able to define the JSON-Encoder pony uses to write json fields to the database.
And for the return-ticket: I would like to specify the object_hook parameter of the json.JSONDecoder-Object used to read the JSON code back from the DB.
Is this possible?
Thank you!

Alexander
04.05.2017
11:02:43
Hi Kristian! How you want to represent Decimal values in JSON fields?

Google

Kristian
04.05.2017
11:05:26
This depends on the use case. Probably as (specially marked?) string or float. (Which means of course, that during reading, all floats will be casted to decimals.)
Similar problems arise with e.g. datetime.datetime.

Romet
04.05.2017
11:12:23
if you're using the Decimal type you really want to use strings
there's no point in it otherwise, you'll be missing out on precision which is kind of its entire point

Kristian
04.05.2017
11:19:56
Well, in JSON it's all a string, right?
{ 'd': Decimal('10.000000000000000001') }
-> '{ "d": "10.000000000000000001" }' or
-> '{ "d": 10.000000000000000001}'
In both ways, no precision is lost. I would assume it will only be lost when a default decoder does
'{ "d": 10.000000000000000001}' -> {'d': float(10.)}
but not when I give an object_hook to json.JSONDecoder which converts numbers.
But you have a point: At least in Postgres Pony uses jsonb, so '{ "d": 10.000000000000000001}' will probably loose precision in the Database, as the database will interpret it as float.


Alexander
04.05.2017
11:22:53
Pony allows to query JSON fields in queries, like
select(obj for obj in MyObject
if obj.json_field[x][y] > z)
In such queries we expect that JSON items have the same type in Python and in the database. If values can be converted to some other type when loading from the database it may be surprising and non-intuitive.
Maybe, it is better to perform such conversion explicitly. Say, you know that some fields are stored as strings, but actually datetime or decimal values, and convert them to that type when you read that JSON value

Kristian
04.05.2017
11:26:27
Hm, ok, I see. I never understood the magic that translates these generators to sql. Thanks anyway, I will use the explicit way, converting them manually.

ltlazz
04.05.2017
17:13:59
Hey, sorry to interrupt can someone help me with creating ERD on a database?

Janis
05.05.2017
08:31:05
This is some part of python code in a project of me: