SQLAlchemy and update data using ORM
August 17, 2009 | databases, pythonauthor: Karol Zielinski | comments: 0 | views: 960
Tags: python, sqlalchemy, update
I was looking for some method to update data using SQLAlchemy‘s ORM. And? I didn’t find any usefull informations in SQLAlchemy’s documentation. That’s why I started to looking for some informations using google and…
So… in quick example:
if I want to add data to my database…
cm = Some_Object() cm.column1 = column1_data cm.column2 = column2_data cm.column3 = column3_data Session.add(cm) Session.commit()
and when I want to update data…
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()
So… SQLAlchemy “knows” what we want to do
Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.