ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.65k stars 245 forks source link

Support for Update API #639

Open mkmoisen opened 2 years ago

mkmoisen commented 2 years ago

In PonyORM, the only way to perform an update in the database is to first get an object, manipulate it, and commit.

There is currently no way to perform generic updates on a single record without pre-selecting it, or bulk updates on many records.

Does PonyORM plan to support this? SQLAlchemy, Django, Peewee, etc. all support this.


It is often nice to to perform an update without first selecting the object from the database, since it save a round trip to the database, and can additionally verify authorization.

For example, in most ORMs we can do a single update statement and check the authorization in one trip to the DB:

UPDATE car
SET make = 'Toyota'
WHERE id = 1
    AND owner.id = :owner_id

In Pony, this would require two queries:

car = Car[1]  # first query SELECT
if car.owner.id == authorized_owner_id:
    car.make = 'Toyota'

commit()  # second query UPDATE

And bulk updating of course is important to support. Looping and updating one by one is too slow.

paxet commented 2 years ago

And bulk updating of course is important to support. Looping and updating one by one is too slow.

According to the documentation, it will be supported in the future. https://docs.ponyorm.org/working_with_entity_instances.html#updating-an-object

mkmoisen commented 2 years ago

Hi @kozlovsky , is there any work being planned regarding an Update API?

goDeni commented 2 years ago

And bulk updating of course is important to support. Looping and updating one by one is too slow.

According to the documentation, it will be supported in the future. https://docs.ponyorm.org/working_with_entity_instances.html#updating-an-object

3 years ago... https://github.com/ponyorm/pony/issues/443