1 00:00:00,000 --> 00:00:04,403 [MUSIC] 2 00:00:04,403 --> 00:00:05,258 Once upon a time, 3 00:00:05,258 --> 00:00:08,908 if you needed to interact with a database, you had to write SQL, Sequel, or 4 00:00:08,908 --> 00:00:13,630 Structured Query Language, which is the language that most common databases speak. 5 00:00:13,630 --> 00:00:18,320 SQL is amazingly powerful, but for day to day tasks, it can be pretty daunting, and 6 00:00:18,320 --> 00:00:22,110 it's definitely a great way to shoot yourself squarely in the foot. 7 00:00:22,110 --> 00:00:24,890 Since most of us like not shooting ourselves in the feet, 8 00:00:24,890 --> 00:00:27,580 we have great software projects known as ORMs. 9 00:00:28,620 --> 00:00:31,430 It's an acronym that stands for Object Relational Mapping. 10 00:00:31,430 --> 00:00:34,150 Sadly, the words don't make it make sense right away. 11 00:00:34,150 --> 00:00:36,600 It's a piece of software that turns objects in your code, 12 00:00:36,600 --> 00:00:39,440 into rows in your database, and vice versa. 13 00:00:39,440 --> 00:00:43,460 They do this by defining a model, that represents a table in our database. 14 00:00:43,460 --> 00:00:45,940 Models, which will be classes, have attributes, 15 00:00:45,940 --> 00:00:48,350 which become the columns in the table. 16 00:00:48,350 --> 00:00:52,140 Every time we call save on a new instance of our class, we add a row to the table. 17 00:00:53,440 --> 00:00:56,800 We're going to be using a lightweight ORM for Python named Peewee. 18 00:00:56,800 --> 00:00:58,190 That was created by Charles Leifer in 2010. 19 00:00:58,190 --> 00:01:00,630 It just so happens too, 20 00:01:00,630 --> 00:01:04,700 that a lot of this course is inspired by a tutorial written by Charles Leifer. 21 00:01:04,700 --> 00:01:06,400 Obviously I own a lot of things. 22 00:01:06,400 --> 00:01:07,050 Thanks Charles. 23 00:01:08,090 --> 00:01:11,090 Peewee is already installed in workspaces, but if you're working along on 24 00:01:11,090 --> 00:01:12,840 your own computer, you'll want to install it yourself. 25 00:01:14,140 --> 00:01:16,050 You'll do that with pip install peewee. 26 00:01:17,250 --> 00:01:19,060 As for the database we'll be connecting to, 27 00:01:19,060 --> 00:01:21,310 we're going to use SQL Lite on Workspaces. 28 00:01:21,310 --> 00:01:23,880 It's a great database for development, because it's lightweight and 29 00:01:23,880 --> 00:01:26,520 starting over is as easy as deleting a file. 30 00:01:26,520 --> 00:01:27,690 If you already have Postgres, or 31 00:01:27,690 --> 00:01:31,560 MySQL database servers set up and want to use them, feel free. 32 00:01:31,560 --> 00:01:32,870 I'll link to the Peewee docs, for 33 00:01:32,870 --> 00:01:35,640 how to connect to those databases in the teacher's notes. 34 00:01:35,640 --> 00:01:37,600 If you're completely freaked out by databases, 35 00:01:37,600 --> 00:01:41,500 be sure to check out our databases course, which I'll also link to in the notes. 36 00:01:41,500 --> 00:01:44,260 If you're still with me, let's go see how to start with Peewee, and 37 00:01:44,260 --> 00:01:46,060 the wide world of databases with Python.