SEQUELIZE
ORM for Node.js
@khriztianmoreno
FullStack Javascript Developer
I'm a community leader and altruistic speaker, JavaScript evangelist. Currently co-organize Medellin.js (Biggest JavaScript user group in Colombia), Avanet and .NETConf.
Object-Relational Mapping
A layer between the application and persistence
Avoid the need to write raw SQL
Become
Another commercial solutions
JAVA
PHP
.NET
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, SQLite and Microsoft SQL Server. It features solid transaction support, relations, read replication and more.
Sequelize is available via npm
Represent tables
You can set options on each column
Data Types
You can specify associations between multiple modules
Automatically create indexes to control the relationship between tables
Connect one source with exactly one target.
Methods belongsTo() and hasOne().
Connect one source with multiple targets.
Targets however are connected to only one source.
Connect multiple resources with multiple targets
Will create a new model called ProjectUsers
You can specify the name of an existing join table
You can also add attributes to the join table
Because Sequelize is doing a lot of magic, you have to call Sequelize.sync after setting the associations!
find() // returns a single entry
findOrCreate() // Check if an element exists and if not, create it
The success callback function will receive the retrieved/created user and the flag 'created'
findAndCountAll() // Returns an object with two properties, the total number of records and an array of objects containing the records
findAll() // Search for multiple elements in the database