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:
- First, we write our Sequelize, using Javascript objects to mimic the structure of our database tables.
- Sequelize creates a SQL string and passes it to a lower-level library called
pg
(PostgreSQL). pg
connects to your PostgreSQL database and queries it or transforms its data.pg
passes the data back to Sequelize, which parses and returns that data as a Javascript object.