SQLAlchemy: Check if object is already present in table
python, python-3.x, sqlalchemy
Solution
The most efficient way is to use exists()
q = session.query(Item.id).filter(Item.email==email)
session.query(q.exists()).scalar() # returns True or False
Problem
I have a class `Item` whose `id` is a primary key and auto-generated. Now I read data from some other external source, create an `Item` object, and need to check if this object is already present in my `items` table. How do I do it?