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
Alexander
Alexander
Lucky
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!
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 😏
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
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.
Lucky
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
Lucky
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
Lucky
Lucky
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
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
Roman
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
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.