Samrat Man Singh Samrat Man Singh - 7 months ago 7
SQL Question

How to query database by id using SqlAlchemy?

I need to query a SQLAlchemy database by its

id
something similar to


User.query.filter_by(username='peter')


but for id. How do I do this? [Searching over Google and SO didn't help]

Answer

Query has a get function that supports querying by ID.

For example, to query for an object with ID of 23: User.query.get(23)

Comments