Python for the .NET developer Transcripts
Chapter: Database access and ORMs in Python
Lecture: SQL query equivalents

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's round out this chapter on SQLAlchemy
0:02 by showing you some more advanced query syntax.
0:06 It was pretty cool that we could say
0:07 guitar.style == style, and that was great.
0:11 But when it gets more complicated
0:13 how do you do that, right?
0:14 How do I do, like, an in clause a not-in
0:18 or how do I do maybe a greater than or something like that?
0:21 Right, substring matching and so on.
0:23 So here are some of the more common ways
0:25 where you might want to do a query.
0:28 So the first one is equals.
0:30 So that's just ==.
0:31 Not equals is !=, straightforward.
0:35 Like, on the name or on the column
0:37 in this case it's the name.
0:39 On the column, we saw they have .des for descending.
0:42 We'll also have like.in_.
0:46 You may wonder why there's an underscore on the end of in.
0:49 The reason is in is a keyword.
0:51 In Python, it's not very selective
0:54 about when it thinks a keyword is a keyword, right?
0:56 There's no context, so in just basically cannot be used
0:59 so they use in_.
1:02 You see, like, class_ or _class.
1:05 Sometimes like when CSS, if you've got to specify
1:08 CSS class and code, you can't use the word class.
1:11 Anyway, we're going to say, we would like
1:12 to go find out if the name is in this array
1:15 or list here, or not in.
1:17 Notice the tilde in the front of the query.
1:20 It's null; it's equal to None.
1:22 Now, you can do ands by doing multiple filters
1:24 or you can do an or, a little bit more complicated
1:27 by calling the or function.
1:28 This is just some of the stuff you can do.
1:30 When you check out the docs
1:31 the link is at the bottom below
1:33 there's a bunch of things you can do.
1:35 It's a very, very flexible system.
1:38 Finally, get the full story.
1:40 SQLAlchemy is created by Mike Bayer
1:42 and a long time ago, can't believe it
1:44 back in April of 2015, I interviewed him
1:48 about what he's been doing in SQLAlchemy, the origins.
1:50 So back then, it was created in 2005
1:53 that was the 10 year anniversary of it.
1:55 If you want to listen to the creator of SQLAlchemy
1:58 talk about it, why he created it
2:00 his thoughts on unit of work, for example
2:02 drop in over at Talk Python To Me
2:04 and listen to this interview with Mike Bayer.