Santosh
Santosh
Entity defination
Alexander
What version of MySQL are you using?
Santosh
It's AWS RDS with 5.7.26
Santosh
Requirement is I have two Json object, I need to filter if just one key from the other json exists
Santosh
Santosh
I tried this
Santosh
But This doesn't meet my condition, if atleast one key exists
Alexander
So, if current_user.access_permission has several keys, you want to check that at least one key present?
Santosh
Santosh
This would fail with error JSON has not attribute keys
Alexander
You need to construct query manually from strings, to use OR, something like: key_list = list(current_user.access_permissions.keys()) users = users.where(" or ".join("key_list[%d] in u.access_permissions" % i for i in range(key_list)))
Santosh
Oh thanks this has helped a lot
Damiano
Are migrations something that will come soon?
Alexander
I hope so. We are working on it, it is hard to tell the exact dates
Damiano
And then, how do I add a column to an already existing table which I don't want to recreate?
Alexander
What database do you use?
Alexander
For simple cases you can do alter table mytable add column newcolumn <type>
Alexander
Note that optional string attributes in Pony are not nullable by default: alter table Person add column middle_name text not null default ''
Damiano
And what if I already have an existing and unused column that I would like to edit?
Damiano
At least its name
Иван
Hello, is there a similar community in Russian?
Alexander
No, only in English
Иван
ok, thx
Santosh
I am seeing peculiar issue I have entity as below Class User(db.Entity): Name = Required (str) Id = PrimaryKey (str) Creator = Optional("User", reverse="creator") Updator = Optinal("User", reverse="updstor")
Santosh
I create data I see all
Santosh
After some time self reference fields become null
Alexander
Parobably you assign None to them somewhere in your code
Alexander
Or, as another option, you delete "creator" or "updator" users
Alexander
And in this case null will be assigned automatically
Santosh
I am running code on AWS lambda and have created DB session for each request with optimistic = True
Santosh
I am suspect something with DB session and not sure if I have set at right place
Santosh
If the Db session of previous request is alive and if I get another request I use same db session
Alexander
Actually, this entity definition looks very strange.The relation creator <-> updator is one to one. The updator meaning looks unclear. If you create a third object and assign the same creator to it, the creator in previous object is set to null automatically, as the relations is 1:1 a = User(Name='A') b = User(Name='B', creator=a) c = User(Name='C', creator=a) # now b.creator is None
Alexander
Maybe you want something like class User(db.Entity): name = Required (str) id = PrimaryKey (str) creator = Optional("User", reverse="users_created") users_created = Set("User", reverse="creator")
Alexander
Now multiple users can have the same creator
Volbil
Hello there guys, is there a way to specify custom name for many-to-many intermediate table?
Alexander
Yes, class Student(db.Entity): courses = Set("Course", table="table1") class Course(db.Entity): students = Set("Student") It is enough to specify it on one side
Volbil
Thanks!
Volbil
Just tested, work like a charm
Volbil
Pony is hidden gem, probably the best orm I worked so far :)
Alexander
Thanks :)
Michele
Hi how can I store a telegram group id on a database? Int is not working
Alexander
Whats group_id in telegram looks like?
Alexander
try group_id = Required(int, size=64)
Michele
Alexander
No problem, you're welcome
Kyle
Hi
Kyle
Kyle
Is this available ?
Alexander
Not yet
Alexander
You can write raw update manually db.execute(""" update mytable set mycolumn = ... where ... """) but be careful, as objects already loaded in current db_session will not see the changes
Kyle
db.raw_sql won't work?
Alexander
It works for select, but not for update
Kyle
Ok, thanks
Genesis Shards Community
why return json whit serialization
Alexander
pony.orm.serialization was an experimental unofficial module, it is not supported
Young
create models from an existing db? like ef core db first ?
Lucky
If I itterate over the rows of db.execute, will orm.commit() # send data to database orm.rollback() # clear data from local cache influence that?
Alexander
Probably you need flush instead of rollback
Kyle
Hi
Kyle
Kyle
is this normal or maybe my fault?
Kyle
Also parse_value
Alexander
It is hard to say, it depends in your columns & data. Some types may require conversion between Python and MySQL
Kyle
I have mutiple intengers type
Kyle
small, tiny, big, and normal ints
Kyle
Varchars and Varbinaries
Kyle
Also dates
Kyle
In the most accessed table
Alexander
I think Pony validate methods should not do any complex conversions for these types
Kyle
I have like 10 relations