Sequelize
ORM for Node.js
What is ORM
• Programmatic way to connect our code to DB and manipulate data
• Developer - focus on business logic
• When an object is read, created, updated, or deleted, the ORM constructs and executes
a database query under the hood
• Comes with advanced features – connection pooling, transaction support, migrations etc
• Work with multiple DBs – postgres, mysql, sqllight
Cons-
• Overhead of learning
• Initial configuration takes time
• Developer wont be knowing what is happening under the hood
Why Sequelize ?
• Different ORMs available – TypeORM, Prisma, Sequelize, BookShelf
• Prisma –
• Auto-generated query builder ,
• Graphql support with all queries for CRUD operations
• Support less DBs compared to other ORMs.
• Not matured compared to other ORMs, some features are in experimental
• Some datatypes like json, array, timestampZ are not supported
• TypeORM –
• traditional ORM
• Good support for Typescript and latest JS features.
What Sequelize provide
• Promise based
• Support for multiple DBs
• DB sync
• DB migrations
• Model hooks
• Associations – belongsTo , hasMany, hasOne, belongsToMany
• Transaction support
• Raw queries
• Easy to test
• Rich Documentation
• Stable
How Sequelize works
• Install Sequelize
• Connect to DB
• Create Model for mapping
• Mapping Model to DB- sync (Model First Approach)
• CRUD operations.
More Details -
https://sequelize.org/v5/index.html
DEMO
Thanks