Christian
I cannot thank you enough for this constant, awesome support here. There were a few ideas in your example that did things differently from my approach. It's not just Pony, I'm learning how to write better code in general. Thank you so much for taking the time to again and again write detailed example code, I really appreciate it! 😌
Alexander
You are welcome :)
Volbil
Hey @metaprogrammer I have another question, I got this error: pony.orm.core.ConstraintError: Cannot unlink Input[8834207] from previous Output[10293640] object, because Input.vout attribute is required Database models looks like this: class Input(db.Entity): transaction = orm.Required("Transaction") vout = orm.Required("Output") class Output(db.Entity): _table_ = "chain_outputs" amount = orm.Required(float) address = orm.Required("Address") vin = orm.Optional("Input", cascade_delete=True)
Volbil
I thought cascade_delete=True will prevent this constraint error since input will be deleted before output is but seams like I was wrong
Volbil
Everything works perfectly fine in single thread
Matthew
Are there any known problems with using pony with AWS Aurora Serverless (Postgres version)?
Milind
Is there a way to integrate Pony with an async application? I am making a discord bot using Discord.py so I was looking for a good asynchronous ORM for Postgres.
Milind
https://docs.ponyorm.org/integration_with_fastapi.html#async-and-db-session
That just looks like a workaround for using it, will I be better off with Tortoise?
El Mojo
That just looks like a workaround for using it, will I be better off with Tortoise?
yes, pony doesn't support async for now ; the developers of the project are focused on migrations for now ; so if you're concerned about async, i suggest using sql-alchemy (more maturity)
Santosh
I have json column defined in entity, Json structure is an array of dictionary like [{'name':'foo', 'age': 35, 'gender':'male'},{'name':'bar', 'age': 45, 'gender':'male'}] Now how do I query for age filed in Json @metaprogrammer request your help
Santosh
Anyone please suggest me the possible solution
Matthew
Product.select(lambda p: p.info['age'] > 5)
Matthew
https://docs.ponyorm.org/json.html#querying-json-structures
Matthew
Oh I misread that as a simple dict
Santosh
Yes it's not simple dict, it's list of dict
Santosh
MySQL
Alexander
MySQL does not have an easy way to implement this type of queries You can try something like the following (not tested): age = 42 select(obj for obj in MyEntity if raw_sql( "$age IN JSON_EXTRACT(obj.json_column, '$$[*].age')" )) But it is probably much better to store this name/age/gender information in a separate entity which is linked to the original entity via relation
Alexander
I think overusing JSON can hurt performance even more. Native database columns can be indexed more easily, and with JSON many of your queries can require a full table scan
Santosh
Currently I am querying by native columns, further filtering of JSON data, I am doing I program, not in SQL, suggest me if this approach is okay
Matthew
it's fine to a point but there's no substitute for using tables as the data gets more complex
Santosh
Okay
Santosh
Understood
Jeff
Lets say I have some records like athletes related to a team. That team has records in a table called matches. I'm wondering what would happen to those records in matches if I switch an athlete from one team to another.
Jeff
Would there be any risk of those records in matches being deleted which include a former team member in a particular match record?
Alexander
In general in this case i suggest you to have intermediate table between athlete and team, which will be repsresenting face athlete being a part of team (with dates and some other information, like number on t-shirt). But on your previous question - no, matches will be deleted if you delete table Team. In case you have 'on delete cascade'
Yuvraj
hey why dont we switch the pony orm community from telegram to discord because discord has more active users than telegram
Volbil
Discord usually requires more time for managing different channels and etc
Volbil
Hello @metaprogrammer I have question regarding count function in Pony. I noticed that calling count function is much slower than running raw SQL query SELECT count(*) FROM table;
Volbil
Is there any way to improve speed of count function?
Alexander
Hi! What database do you use? How do you call the count function?
Volbil
At the moment I use SQLite as test database. For comparison I used orm.count(t for t in Transaction) code and raw SQL query SELECT count(*) FROM chain_transactions; which I ran inside sql management tool I use.
Volbil
Raw query executes in around 0.01 second
Volbil
But for Pony count function takes around 1 second
Volbil
SELECT COUNT(DISTINCT "t-1"."id") FROM "chain_transactions" "t-1"
Alexander
It looks strange, maybe the database was blocked by some concurrent transaction?
Volbil
It looks strange, maybe the database was blocked by some concurrent transaction?
Not really, only thing which uses database is test script
Alexander
DISTINCT is unnecessary here. Looks like a bug. Thanks for reporting!
Volbil
DISTINCT is unnecessary here. Looks like a bug. Thanks for reporting!
Ok, I did Transaction.select().count(distinct=False) and it runs much faster now, thanks :)
Volbil
But yes, looking at the docs it should be False by default
Volbil
👨🏼‍💻Vasiliy Rusin
Hello, I try to use order_by by datetime type, and I get "TypeError: Unsupported type 'datetime'". After that, I tried to create hybrid property to convet datetime to integer, but I also get this error (already in property). Does it have any workaround to order by datetime field?
Alexander
Can you show an example?
👨🏼‍💻Vasiliy Rusin
Can you show an example?
Sorry for delay, while I tried to create example I suppose what I found the problem. I create subclass for datetime which works with UTC time by default, so its type still is "datetime" but "datetime is not (my) datetime". So itn't pony error. But maybe pony should check primitive types throught "subclass", same as "is".
Volbil
Hello again @metaprogrammer, I have little question about best practices when using pony. I have set in my model which looks like this transactions = orm.Set("Transaction"). What would be best way to count it: len(self.transactions or self.transactions.count() ?
Volbil
Basically does it matter if I use len instead of .count() ?
Alexander
len does a single query to fetch all items and return length count just calculate total count, but does not retrieve individual items if you need to iterate over all items in the same transaction, use len if you just need to know total count, use count
Genesis Shards Community
Ok
Volbil
Hello again @metaprogrammer I have another question regarding Pony. I've been using SQLite as my test database and it worked fine with timedelta values but now I switched to MySQL and got OperationalError: 1292 Incorrect time value: '1033:48:45' for column 'activetime' at row 1 error for same timedelta value.
Volbil
Is there any pitfalls I should be aware when using timedelta inside MySQL?
uvicorn
is editor.ponyorm.com open source ?
uvicorn
no
=(
uvicorn
why?
El Mojo
Because they need money to keep the project online
Christian
But it's free to use for public diagrams.
Anonymous
When using Oracle, why does the pony declare "str" columns like... VARCHAR2(1000 CHAR) ? (insead of just ```VARCHAR2(1000)```)
Anonymous
When using Oracle, why does the pony declare "str" columns like... VARCHAR2(1000 CHAR) ? (insead of just ```VARCHAR2(1000)```)
nm - https://community.oracle.com/tech/developers/discussion/2379822/difference-between-byte-char
Ben
Howdy! I'm getting a new strange assertion error
Ben
The error is: 'assert t is translator' on line 229 of sqltranslation.py in pony code. I'm on version 0.7.14 and using Postgres.
Alexander
Hi, what's your query?
Alexander
Also - some cases were fixed few months ago. @metaprogrammer was fix released?
Alexander
Also - some cases were fixed few months ago. @metaprogrammer was fix released?
I think the fix wasn't released yet. We should make a release in a few days
Alexander
Not yet
El
Hello, Sorry if the question has been asked thousand times, but can't find my mistake from pony.orm import * set_sql_debug(True) db = Database() db.bind( provider='postgres', user='postgres', password='example', host='0.0.0.0', database='test' ) class Content(db.Entity): id = Required(int, auto=True) kind = Required(str) title = Required(str) description = Optional(str) picture_url = Optional(str) picture_cache = Optional(str) parent_id = Optional(int) PrimaryKey(id, kind) db.generate_mapping() new_channel = Content( kind='channel', title='TF1', description="Channel TF1", picture_url="/img/pictures/211267/", picture_cache="" )
El
TypeError: 'NoneType' object is not iterable
El
Ok found the answer in this thread https://t.me/ponyorm/3908
El
Finally it is not the same error
Ben
Hey! Is there a known bug in the current version about pony throwing "KeyError" issues about keys that totally exists in the model?
Alexander
Pls show the line of code and complete traceback