水曜日, 3月 31, 2010

SQLAlchemy and update data using ORM

SQLAlchemy and update data using ORM

Insert to database

cm = Some_Object()
cm.column1 = column1_data
cm.column2 = column2_data
cm.column3 = column3_data

Session.add(cm)
Session.commit()



Update database

cs = Session.query(Some_Object).filter(and_(Some_Object.id == some_id,Some_Object.other_id == some_other_id)).one()

cs.column1 = "abc"
cs.column2 = "qwe"
cs.column3 = "asd"

Session.add(cs)
Session.commit()

0 件のコメント: