karikris...@gmail.com wrote: > At present, I use the following way to find whether db contains a > record or not. I know that this will create MyModel instance and fetch > the db info and set the mymodel with db values if the record exists. > Are there any lighter way to check it. just a simple boolean return? > And id is primary key for me so there would be no question of query > returns more than one item. > > try: > session.query(model.MyMode).filter_by(id=id).one() > print 'found' > except: > print 'not found'
session.query(exists([model.MyMode.id])).filter_by(id=id).scalar() or bool(session.query(model.MyMode).filter_by(id=id).count()) > > regards, > > Krish > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.