Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Course conclusion
Lecture: Querying data
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
We saw how nice and powerful it was to model our database in terms of Python classes and then use SQLAlchemy to run queries against that.
0:10
So, here we have a find_account_by_login. And we're going to get an email and a password. And in this in case, we're not doing the path load stuff
0:17
probably not the way we should do it but just in this little example we can directly compare the hashes. So we go and create our session.
0:24
Remember, we use the unit of work design pattern. So we do that by creating the session and then we go to the session create a query based on a class
0:32
so we're creating an account query. Then we say we'd like to do a filter where the class.email == the passed-in email
0:38
and then we're chaining on an "and" condition another filter where the password hash equals the hash.
0:45
What we'll see at the bottom is something roughly equivalent to select * from account where account.email equals what were
0:52
push parameter, and account.password_hash is second. And the params are michael@talkpython.fm and my favorite password, abc.
1:00
We thought it's actually a little bit more complicated. It states out all the columns and whatnot but that's roughly the idea
1:06
and this is how we use SQLAlchemy. Highly recommended.