Mastering PyCharm Transcripts
Lecture: Data application introduction
0:01 Now, in order to make working with the database tools interesting
0:04 and have real data, I created this simple little application that we can play with,
0:09 some of which I copied from a previous class, some of which I wrote from scratch.
0:13 So, if you look here, we've got our main method
0:18 it sort of sets up some data access stuff and then it calls list_albums,
0:22 and notice, this may look familiar to you, this is a SQLAlchemy statement
0:27 so we're creating a database session
0:30 and we're creating a query based on the album class
0:34 which is a model mapped into the database,
0:38 and we're getting everything, we'll just order
0:40 by the name descending, reverse alphabetical
0:43 and then we're just looping over them
0:45 and we're actually traversing a foreign key relationship over to a track table here,
0:50 we're not actually pulling back the tracks, but we are doing a length on them.
0:54 So first, let's run this, you can see, nothing super exciting,
0:57 there are two albums in our database,
0:59 the Year of The Snake, which has five tracks
1:02 and Digital Age Boys and Girls, six tracks.
1:04 Okay, so this actually comes from my Python for Entrepreneurs class,
1:08 The Blue Yellow Rockets app is a thing we built,
1:11 so let's just look super quick, we're using SQLALchemy,
1:14 there is nothing in the tooling that really matters around SQLAlchemy
1:17 we're just happy to be playing with it through there.
1:20 So over here we have an album class
1:23 which derives from SQLAlchemy base, it's mapped to the table album
1:25 and it has a bunch columns, and interestingly,
1:28 we've got indexes and uniqueness constraints
1:32 and things like that, like the name is indexed and it has to be unique.
1:36 Similarly over here, we've got our albums
1:40 and there's a foreign key relationship from the album id back to the album's id.
1:45 Alright, so that generated this database over here
1:49 you can see we're basically connecting to SQLite
1:54 and we could connect to lots of different databases as we'll see,
1:58 but connecting to SQLight means there's really no server for you to set up
2:01 so it's as easy as it can be to play this demo.
2:04 With that in place, what we're going to do really is
2:07 explore the data that was created by this application in this little database
2:12 and we'll do that in the next couple of sections.