ORM & Using Sequelize ORM with Express (Node.js)

Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages(WIKI).ORM converts data between type systems that cannot co-exist.

Sequelize is a promise-based ORM (Object relation model) for Node.js. It supports the dialects PostgreSQL, MySQL, SQLite, MSSQL and features solid transaction support, relations, read replication and more. For creating sequelize connection in Express, use the following code. Here we create a connection to ‘user’ database

Now create a folder ‘model’ . For each table in the database we create a model file. In our example, we have a users model


Now Create an index.js file inside the model folder

Now the above code in index.js file helps us use all model files inside our model folder.

For understanding more about sequelize, refer  http://docs.sequelizejs.com/

How to  handle errors in sequelize query

Consider the below example in which we do a CREATE which insert data into  a table








Leave a Reply

Your email address will not be published. Required fields are marked *