Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll talk about what ORMs are, what Sequelize is and what we're going to build.
Node.js ORMs
Treehouse Content
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
Hello.
0:04
Andrew here, node.js developer and
teacher here at Treehouse.
0:05
In this workshop we're going to talk
to a SQL database with node.js.
0:09
While a document based
database is like Mongodb,
0:14
fairly popular with node.js developers.
0:17
SQL databases are still a major
component in many applications.
0:20
Understanding how to use SQL databases
in a Node.js application is a vital
0:25
skill to have, no matter what language
you deal with whether it'd be Java,
0:29
Ruby, Python or JavaScript.
0:34
You'll come across a particular group
of software tools called ORMs, or
0:37
objects relational mapping libraries.
0:42
That allow you to interface with
the SQL database in any given language.
0:44
In our case,
It's JavaScript on the node.js platform.
0:49
There are several ORMs available in
node.js, the SQLite, bookshelf and Knex.
0:54
Once you have learned the basics of one
ORM, you can apply them to any of them.
1:00
We're going to look at
a popular ORM called Sequelize.
1:04
Sequelize can be used for SQLite, MySQL,
1:08
PostgreSQL and Microsoft's
Sequel Server Database Systems.
1:12
Sequalize is a promise based ORM.
1:18
If you're not familiar with JavaScript
promises, check the teacher's notes linked
1:21
to Treehouse learning material
that covers promises.
1:25
ORM's generally provide key
functionality to help you maintain and
1:29
interact with databases.
1:33
This functionality includes
the creation of tables,
1:35
all the CRUD operations, and
the ability to validate user input.
1:39
We're going to take a look at all
of these throughout this workshop.
1:43
For this workshop, we'll make a blog.
1:47
It's going to have a page
that lists all the articles,
1:49
a new article page, an edit page,
and a way to delete an article.
1:52
We're basically performing all the CRUD
operations, create, read, update, and
1:57
delete, using a web interface.
2:02
Here is the beginning
state of application.
2:05
Launch the workspace associated
with this video and check it out.
2:09
All the code that handles the routes and
the views are done.
2:13
All we need to do is
the work on the database.
2:18
Let's look up the articles routes.
2:21
I've included some static articles here,
so
2:24
you can see what the pages
should look like.
2:26
They both have helper methods
that form at the publishdats, and
2:30
the shortdescription displayed
on the articles listing page.
2:33
I also have a find function that returns
the article when passing in an ID.
2:37
We'll be removing these
static articles and
2:42
the find function when we use a database.
2:44
With each of the routes the response code
will stay the same when we're adding
2:50
the database code.
2:54
Any code before them is just
to make the application work
2:56
with these in memory articles.
2:59
We won't need this code when we're
implementing our database code.
3:01
Before moving on to the next video,
familiarize yourself with the code.
3:06
Once you're ready,
we'll start adding the database code.
3:10
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