Building data-driven web apps with Flask and SQLAlchemy Transcripts
Chapter: MongoDB edition
Lecture: The rest of the entities
0:00 Over here in our NoSQL folder
0:01 we have our setup and we have our users.
0:03 But there's a bunch of stuff we need
0:04 like packages and maintainers and licenses.
0:08 You saw how easy it was and how similar this was
0:10 to SQLAlchemy for users.
0:12 Let me just drop in the rest.
0:13 There's no reason to watch me type it all out.
0:15 So we can go through.
0:16 And here we have the downloads which are straightforward.
0:20 I guess we don't need table name anymore.
0:22 We've got package_id and release_id and all these things.
0:26 And of course we're setting up indexes on them.
0:29 Languages, this is again similar to what we had before.
0:33 Licenses also. You are overwriting the type of key
0:37 which is certainly possible
0:39 something you can do just like we are in packages.
0:42 Over here, we're setting the string field
0:43 to be a primary key.
0:45 This, let's just store a string
0:46 instead of that object ID type of thing.
0:49 And everything along here looks pretty much the same
0:51 as it was in SQLAlchemy
0:52 but here's where we start to leverage
0:55 the hierarchical aspect of document databases
0:58 over tabular stuff say, in relational.
1:01 Here's our maintainers.
1:02 Previously, we had a maintainers table
1:05 and what it stored was
1:07 project ID, maintainer ID
1:09 and it was just the normalization table
1:11 for the many-to-many relationship.
1:13 We don't have to do that here.
1:14 We can store, actually a list of all the maintainer IDs
1:18 which then are relationships navigating back
1:21 keys back to the user table.
1:24 So we don't need that normalization table
1:25 we know what project we're on
1:27 and these are all the IDs that are maintainers of it.
1:30 And we can do super nice queries down into this list
1:32 and all sorts of stuff like that.
1:34 So we're not leveraging too much among it to be here
1:37 but here's one interesting part of it right there.
1:40 Right, so that's all the other entities
1:42 that we might want to work with.