SQLAlchemy - select for update example

前端 未结 3 1968
太阳男子
太阳男子 2020-12-05 13:01

I\'m looking for a complete example of using select for update in SQLAlchemy, but haven\'t found one googling. I need to lock a single row and update a column, the followin

3条回答
  •  一整个雨季
    2020-12-05 13:56

    If you are using the ORM, try the with_for_update function:

    foo = session.query(Foo).filter(Foo.id==1234).with_for_update().one()
    # this row is now locked
    
    foo.name = 'bar'
    session.add(foo)
    
    session.commit()
    # this row is now unlocked
    

提交回复
热议问题