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
0:02 to model our database in terms of Python classes
0:05 and then use SQLAlchemy to run queries against that.
0:09 So, here we have a find_account_by_login.
0:11 And we're going to get an email and a password.
0:13 And in this in case, we're not doing the path load stuff
0:16 probably not the way we should do it
0:17 but just in this little example we can directly
0:19 compare the hashes.
0:21 So we go and create our session.
0:23 Remember, we use the unit of work design pattern.
0:25 So we do that by creating the session
0:27 and then we go to the session
0:29 create a query based on a class
0:31 so we're creating an account query.
0:32 Then we say we'd like to do a filter
0:34 where the class.email == the passed-in email
0:37 and then we're chaining on an "and" condition
0:40 another filter where the password hash equals the hash.
0:44 What we'll see at the bottom is something roughly equivalent
0:47 to select * from account
0:48 where account.email equals what were
0:51 push parameter, and account.password_hash is second.
0:54 And the params are michael@talkpython.fm
0:57 and my favorite password, abc.
0:59 We thought it's actually a little bit more complicated.
1:01 It states out all the columns and whatnot
1:03 but that's roughly the idea
1:05 and this is how we use SQLAlchemy.
1:07 Highly recommended.