SQLAlchemy: a better way for update with declarative?
Posted
by hadrien
on Stack Overflow
See other posts from Stack Overflow
or by hadrien
Published on 2010-04-13T18:00:27Z
Indexed on
2010/04/13
18:03 UTC
Read the original article
Hit count: 262
python
|sqlalchemy
I am a SQLAlchemy noob.
Let's say I have an user table in declarative mode:
class User(Base):
__tablename__ = 'user'
id = Column(u'id', Integer(), primary_key=True)
name = Column(u'name', String(50))
When I know user's id without object loaded into session, I update such user like this:
ex = update(User.__table__).where(User.id==123).values(name=u"Bob Marley")
Session.execute(ex)
I dislike using User.__table__
, should I stop worrying with that?
Is there a better way to do this?
Thanx!
© Stack Overflow or respective owner