Adding a CMS to Your Flask Web App Transcripts
Chapter: Saving content to the DB
Lecture: Concept: Query for an object with SQLAlchemy
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Once we have things in the database, we need to query the database so we can get them back and work with them
0:05
So what we're gonna do is again the unit work pattern. So we're gonna go to the D V session and create a session.
0:12
I work with that. That's their unit of work. And then we try finally pattern to make sure we close it nice and cleanly,
0:17
no matter what we're gonna take. The data were trying to query with in this case, the URL and normalize it and clean it up because of its upper case,
0:25
it might not match on string equals depending on the type of database using.
0:30
And then we're just gonna go and do the query when a return session dot query of page gonna do a filter page where l is equal to the euro were given
0:38
And then when do you just first, right? Give us one. And if you don't find it, just give us none back pretty easy, right? When we run this code,
0:48
it's going to actually send a translation over to the sequel.
0:52
Were language over the database, it will effectively say Select star from pages where pages
0:58
dot URL equals some parameter. First primary being companies slash history assuming that that's the
1:04
page that we're asking for. So it's really nice that when we write this code
1:07
it gets translated over to the sequel Queer Language instead of like pulling it back
1:12
and doing all memory. That's just the power of sequel Commie and here's how it