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