2 messages in com.googlegroups.sqlalchemy[sqlalchemy] safe way to add value
FromSent OnAttachments
Denis Shaposhnikov25 Mar 2007 23:26 
Michael Bayer26 Mar 2007 17:44 
Subject:[sqlalchemy] safe way to add value
From:Denis Shaposhnikov (ds@vlink.ru)
Date:03/25/2007 11:26:41 PM
List:com.googlegroups.sqlalchemy

Hi!

I have a question. May be someone able to give me advice. For example

users_table = Table('users', meta,

... Column('user_id', Integer, primary_key=True), ... Column('a', Integer) ... )

class User(object):

... pass

mapper(User, users_table) u = session.query(User).get(1)

What's the best way to add some value to `u.a`? I mean, safe way, because several processes want to add some value. Is it possible to do something like

u.a = u.a + 21 session.flush()

and give something like

UPDATE users SET a = a + 21

?

Or do you know some other way?

Thanks!