ORM

Object-relational Mapping is a programming technique used to make more readable the way we use database query statements in other languages different from SQL / NoSQL.

Sequelize - ORM in JavaScript

sequelize is one of the most used libraries to work with ORM in JS. It supports the most used database types like PostgreSQL, MariaDB, MySQL, SQLite and Microsoft SQL Server.

When developing a project, we can follow one of two different patterns defined by Martin Fowler:

Data Mapper

The Entity Model doesn’t interact with the database. It is only there so it can be used by Entity Mapper to make operations in the database (View and Model are separated)

Active Record

The Entity Model interacts with the database. Every method is directly linked, they are all in the same file (View and Model are in the same file).

Sequelize - Starting Up

npm init -y
npm i sequelize sequelize-cli mysql2
npx sequelize-cli init

This last command will create the following folders: /config, /migrations, /models & /seeders.

ORM - Folders & Utilities

ORM - Common Model Operations

ORM - Associations (JOIN)

ORM - Transactions

JWT - JSON Web Token

JWT is a token generated with the HMAC algorithm by codifying some information.

The token generation is based in personal user information and a secret known just by the server.

Into the code