Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Using Databases in Python!
You have completed Using Databases in Python!
Preview
So, what is an ORM and why would you want to use one? Let's talk about that and get our chosen one, Peewee, installed.
Links
- Peewee's docs
- Connecting to PostgreSQL
- Connecting to MySQL
- Database Foundations
- Charles Leifer's tutorial
I heavily suggest checking out other posts on his site. He has some great project ideas!
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Once upon a time,
0:04
if you needed to interact with a database,
you had to write SQL, Sequel, or
0:05
Structured Query Language, which is the
language that most common databases speak.
0:08
SQL is amazingly powerful, but for day to
day tasks, it can be pretty daunting, and
0:13
it's definitely a great way to shoot
yourself squarely in the foot.
0:18
Since most of us like not shooting
ourselves in the feet,
0:22
we have great software projects known as
ORMs.
0:24
It's an acronym that stands for Object
Relational Mapping.
0:28
Sadly, the words don't make it make sense
right away.
0:31
It's a piece of software that turns
objects in your code,
0:34
into rows in your database, and vice
versa.
0:36
They do this by defining a model, that
represents a table in our database.
0:39
Models, which will be classes, have
attributes,
0:43
which become the columns in the table.
0:45
Every time we call save on a new instance
of our class, we add a row to the table.
0:48
We're going to be using a lightweight ORM
for Python named Peewee.
0:53
That was created by Charles Leifer in 2010.
0:56
It just so happens too,
0:58
that a lot of this course is inspired by a
tutorial written by Charles Leifer.
1:00
Obviously I own a lot of things.
1:04
Thanks Charles.
1:06
Peewee is already installed in workspaces,
but if you're working along on
1:08
your own computer, you'll want to install
it yourself.
1:11
You'll do that with pip install peewee.
1:14
As for the database we'll be connecting
to,
1:17
we're going to use SQL Lite on Workspaces.
1:19
It's a great database for development,
because it's lightweight and
1:21
starting over is as easy as deleting a
file.
1:23
If you already have Postgres, or
1:26
MySQL database servers set up and want to
use them, feel free.
1:27
I'll link to the Peewee docs, for
1:31
how to connect to those databases in the
teacher's notes.
1:32
If you're completely freaked out by
databases,
1:35
be sure to check out our databases course,
which I'll also link to in the notes.
1:37
If you're still with me, let's go see how
to start with Peewee, and
1:41
the wide world of databases with Python.
1:44
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up