Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy SELECT id FROM Table_1 WHERE name='xyz'

I can get the SELECT id from parts where name='Part1' as an SQL statement but what is the way to do that with SQLAlchemy?

I've tried;

db.session.query(Parts.id).filter(name=form.name.data)

But this returns an Object not the id

like image 978
Leustad Avatar asked Sep 11 '25 22:09

Leustad


1 Answers

Use the below code.

parts = db.session.query(Parts).filter(Parts.name==Part1).first()

Then if you want the only id you can just access

parts.id
like image 67
SumanKalyan Avatar answered Sep 13 '25 20:09

SumanKalyan