Alexander
Or try select(sum(a.cantidad * a. precio)) for a in Pedido if a.token == _token)
Alexander
@luckydonald I think I don't fully understand what do you want to achieve Maybe you can have two different db instances with different entities which are point to the same physical database. The first system_db is for system entities which should exist from the beginning, and the second user_db for user-defined entities which became known later
Alexander
from settings import db_params sys_db = Database() class SysInfo(sys_db.entity): ... sys_db.bind(**db_params) sys_db.generate_mapping() user_db = Database() define_entities(user_db, info=SysInfo.select()) user_db.bind(**db_params) user_db.geberate_mapping()
Anonymous
How do I edit a relation many to many in the ponyorm designer ? I can only add a new relation, not edit an existing relation.
Jordi
Hi there, I would like to know if it's possible to update instance values in a second db_session without having to use select/get on the second session. And in that case, how I could do it, as the code below is how I thought it would be class Professor(Person): _discriminator_ = “professor” degree = Required(str) students = Set("Student") interest = Optional(‘str’) @classmethod @orm.db_session def inst_professor(cls, **kwargs): return cls(**kwargs) @orm.db_session def add_interest(self, interest): self.interest = ', '.join([self.interest, interest]) if self.interest else interest new_professor = Professor.inst_professor(degree='something') # Doing some stuff here new_professor.add_interest('ML')
Lucky
from settings import db_params sys_db = Database() class SysInfo(sys_db.entity): ... sys_db.bind(**db_params) sys_db.generate_mapping() user_db = Database() define_entities(user_db, info=SysInfo.select()) user_db.bind(**db_params) user_db.geberate_mapping()
In that example I would like to have a table defined in my library, and any programmer could use it additional to his own tables, like this: db = Database() class UserTable(db.Entity): id = Required(int) from telestate.contrib.pony import StateTable db.register(StateTable) Obviously my library can't import the user's setting, as it doesn't know about those.
Alexander
In that example I would like to have a table defined in my library, and any programmer could use it additional to his own tables, like this: db = Database() class UserTable(db.Entity): id = Required(int) from telestate.contrib.pony import StateTable db.register(StateTable) Obviously my library can't import the user's setting, as it doesn't know about those.
Currently you can provide a function and define entities in it: #mymodule.py def define_telestate_entities(db): class StateTable(db.Entity): ... #main.py from mymodule import define_telestate_entities db = Database() class UserTable(db.Entity): ... define_telestate_entities(db) db.bind(**params) db.generate_mapping() The only drawback is that IDE cannot auto-complete entities defined in functions
Alexander
Hi there, I would like to know if it's possible to update instance values in a second db_session without having to use select/get on the second session. And in that case, how I could do it, as the code below is how I thought it would be class Professor(Person): _discriminator_ = “professor” degree = Required(str) students = Set("Student") interest = Optional(‘str’) @classmethod @orm.db_session def inst_professor(cls, **kwargs): return cls(**kwargs) @orm.db_session def add_interest(self, interest): self.interest = ', '.join([self.interest, interest]) if self.interest else interest new_professor = Professor.inst_professor(degree='something') # Doing some stuff here new_professor.add_interest('ML')
You need to wrap all operations in a single db_session: with db_session: new_professor = Professor.inst_professor(degree='something') # Doing some stuff here new_professor.add_interest('ML') Nested db_sessions will be ignored If for some reason you cannot use single db_session, you can make proxy object and pass it to another db_sesson: from pony.orm import make_proxy new_professor = Professor.inst_professor(degree='something') new_professor = make_proxy(new_professor) # Doing some stuff here with db_session: new_professor.add_interest('ML')
Lucky
For the other example where different projects share (some) of the same tables, we could end up wanting to register only some of them, so having several functions for serveral tables
Lucky
I tried implementing such later.Entity blueprint, but got stuck as the code registering a Entity with the Database (db) is deep within EntityMeta, but not in a way which could easily be overwritten, delayed, and called at a later time.
Matthew
Hi, is there any problem with having Pony ORM sessions inside gevent greenlets. Sessions would be self contained and created within a specfiic greenlet. I'd be using postgres
Alexander
Pony can works with threads, and if I understand correctly greenlets are just like threads from application point of view But caution is necessary anyway, because each greenlet will use separate connection to PostgreSQL, and it may be hard for PostgreSQL to hanlde huge number of simultaneous connections Also, I think it is possible that some greenlet perform some update which requires locking, and then suspends for a long time. Anothe greenlets may be also blocked by this lock Maybe you need to explicitly perform db.disconnect() after the db_session to close connection. By default connection remains open to be reused by the following requests handled by the same thread.
Matthew
Ah thank you
Matthew
Would pony automatically reconnect after a manual disconnect if I opened a new session?
Alexander
yes
Pav
Когда уже миграции будут??
Pav
А то без них совсем грустно((
Andrew
English only!
Drop
Когда уже миграции будут??
https://github.com/ponyorm/pony/tree/orm-migrations
Alexander
We are working on it
Matthew
Is there a way to enforce that at least one of several Optional fields is Required?
Alexander
1) In database like PostgreSQL it is possible to manually add named check constraint like: alter table mytable add constraint myconstraint check ( column1 is not null or column2 is not null or column3 <> '' or column4 > 0 ) 2) In PonyORM it is possible to define after_insert/after_update hooks: class MyEntity(db.Entity): foo = Optional(int) bar = Optional(int) def before_insert(self): self.check_fields() def before_update(self): self.check_fields() def check_fields(self): if not (self.a or self.b): raise ValueError
Matthew
Thanks!
Jake A
@metaprogrammer any possibiity to defien constraints like this on PonyORM, and then it could check they exist like it does with columns?
Jake A
Seems like it would be a useful addition, I often need similar things and normally just do it in Python, but seems it would be better enforced at the DB level like your #1 example
Alexander
It would be a useful addition, but I think we need to implement migrations first, as it is better to specify such things in migrations
Matthew
Jake we eagerly await your pull request 😏
Jake A
Jake we eagerly await your pull request 😏
My python programming days are limited recently unfortunately, dont get chance to write much 🙁
Alexander
We are working on migrations now, I think it should be easy to add custom constraints after the release of migrations
Dominik
Can't wait for migrations to become stable. It's a killer feature if we want to see PonyORM widely adopted.
stsouko
PonyAdmin and PonyGraphQL also wanted features
Dominik
Oh, so a full framework, right?
Roberto
We are working on migrations now, I think it should be easy to add custom constraints after the release of migrations
This is great news... Can migrations be tested or it's early stage of development yet?
Alexander
It's in development yet, I hope we can show it in a few months
Genesis Shards Community
Hello,
Genesis Shards Community
Howard do i calcularse a sum?
Genesis Shards Community
Select sum(total) as su from ventas where id=10
Genesis Shards Community
Helpme!
Genesis Shards Community
Please
Alexander
select(sum(x.attr) for x in X if x.id == 10)) I guess
Lucky
'Nother Bug in the editor - Clicking the dropdown closes & deletes the element. I used to select the type first before thinking about a variable name. - Also when clicking the 'X' of the error that creates another error.
stsouko
https://github.com/stsouko/LazyPony hello! I finished designing the extension library for pony. it allows you to separate the declaration of classes and their binding to the database object.
David
So that pony us just a short sql code in python?
David
Is*
Alexey
'Nother Bug in the editor - Clicking the dropdown closes & deletes the element. I used to select the type first before thinking about a variable name. - Also when clicking the 'X' of the error that creates another error.
which behavior would be more appropriate? we remove the attribute without the name on losing focus because if we keep it, generating SQL or Python code would not be possible
Lucky
How about getting red and just refuse to close until something is entered?
I mean the delete button already works if someone doesn't wanna add it after all
Alexey
I see Let me think about it
Roman
Hello guys. Is it possible to integrate Pony to django project?
Lucky
#bug in the #editor: Dropdown goes out of window bounds
Dominik
Hello guys. Is it possible to integrate Pony to django project?
There was a project some time ago but to be honest this does not make much sense since Django and Pony approach ORM from different perspectives.
Lucky
#bug in the #editor: Dropdown goes out of window bounds
That's not a good way to fix that 😅
Lucky
That's not a good way to fix that 😅
The dropdown is in bounds now, though. #bug #editor
Lucky
The dropdown is in bounds now, though. #bug #editor
Happening with "Add new relationship" dialog too.
Lucky
Hey, could we have comment support on a database level? The editor has a Comment field which sadly isn't reflected in the database.
Lucky
Also linebreaks kill your code
Lucky
Also linebreaks kill your code
How about hour_factor = Required(float, default=4, comment="24=daily,\n12=twice a day,\n8=three times a day,\n6=four times a day") or hour_factor = Required(float, default=4, comment="""24=daily, 12=twice a day, 8=three times a day, 6=four times a day""")
Lucky
Which could result in CREATE TABLE "cron" ( "id" SERIAL PRIMARY KEY, "channel" BIGINT NOT NULL, "hour_factor" DOUBLE PRECISION NOT NULL COMMENT "24=daily,\n12=twice a day,\n8=three times a day,\n6=four times a day", ...
Lucky
Hey the new autosave feature is very annoying as it often leads to "Another user saved before you. Confirm to overwrite. Open diagram in another tab to check changes"
Alexander
*panic*
Lucky
Can I turn it of somehow?
Lucky
Also after that, I got a red error message saying saving went wrong. Also the save button turned grey, so I can't click it again to retry saving...
Lucky
Lucky
Also those error messages stack, apprearently it will try over and over while the error message is still open
Lucky
Lucky
Not sure of my computer at home
Lucky
But I don't care about the editor at home, there shouldn't be any changes.
Lucky
Probably it has openend about 20 alerts with the conflict by now, as the autosave continues in the background
Lucky
But I often have it opened multiple times by accident, like multiple times to read it, should be without changes
Roman
Can't reproduce it. but I'll revert update for a while.
Lucky
Can't reproduce it. but I'll revert update for a while.
Yeah race conditions and stuff are very difficult to debug
Lucky
I still think if you have changes, it will even if displaying the error promt continue to try to autosave, thus causing conflicts again and again? I think one easy case would be opening 2 tabs, making changes in both, and waiting for a minute or 3. After that if you cancel away the warnings, you have to cancel multiple, as they stack.
Lucky
Can't reproduce it. but I'll revert update for a while.
I'd already happy with a toggle to be able to turn it off. Could be a user setting or just a checkbox next to the save button
Roman
Yeah race conditions and stuff are very difficult to debug
actually we are checking last_update dt on client and server and compare them. Also autosave do save only if there are any unsaved data.