Skip to content

Instantly share code, notes, and snippets.

View tonystaark's full-sized avatar

Tony Ng tonystaark

  • Kuala Lumpur, Malaysia
View GitHub Profile
@zcaceres
zcaceres / Sequelize-Step-by-Step.md
Last active February 22, 2023 12:53
Let's get an overview of Sequelize!

Sequelize: Step-By-Step

Sequelize is a powerful library in Javascript that makes it easy to manage a SQL database. Sequelize can layer over different protocols, but here we'll use PostgreSQL. At its core, Sequelize is an Object-Relational Mapper – meaning that it maps an object syntax onto our database schemas. Sequelize uses Node.JS and Javascript's object syntax to accomplish its mapping.

Under the hood, Sequelize used with PostgreSQL is several layers removed from our actual database:

  1. First, we write our Sequelize, using Javascript objects to mimic the structure of our database tables.
  2. Sequelize creates a SQL string and passes it to a lower-level library called pg (PostgreSQL).
  3. pg connects to your PostgreSQL database and queries it or transforms its data.
  4. pg passes the data back to Sequelize, which parses and returns that data as a Javascript object.