Sequelize v5.1.0 release, Node.js ORM

Sequelize

When you start building web applications and APIs you often need something that interacts with databases for you. Maintaining relationships between tables, fetching related records and managing transactions gets very repetitive over time when using just raw queries. Sequelize abstracts these tasks away for you and provides you with a database layer.

It provides simple access to  MySQL, MariaDB, SQLite and  PostgreSQL databases by mapping database entries to objects or object-to-database entries. In short, ORM (Object-Relational-Mapper). It is written entirely in JavaScript and is suitable for the environment of Node.js.

It has been under development since July 2010 and is used by a large number of users. It’s under active development with new features introduced relatively often.

Sequelize

Feature

  • Schema definition
  • Schema synchronization/dropping
  • 1:1, 1:M & N:M Associations
  • Through models
  • Promises
  • Hooks/callbacks/lifecycle events
  • Prefetching/association including
  • Transactions
  • Migrations
  • CLI (sequelize-cli)

Sequelize v5.1.0 has been released. The update change as follows:

Breaking Changes

Support for Node 6 and up

Sequelize v5 will only support Node 6 and up #9015

Secure Operators

With v4 you started to get a deprecation warning String based operators are now deprecated. Also concept of operators was introduced. These operators are Symbols which prevent hash injection attacks.

http://docs.sequelizejs.com/manual/querying.html#operators-security

With v5

  • Operators are now enabled by default.
  • You can still use string operators by passing an operators map in operatorsAliases, but that will give you deprecation warning.
  • Op.$raw is removed

Typescript Support

Sequelize now ship official typings #10287. You can consider migrating away from external typings which may get out of sync.

Pooling

With v5 Sequelize now use sequelize-pool which is a modernized fork of generic-pool@2.5. You no longer need to call sequelize.close to shutdown pool, this helps with lambda executions. #8468

Model

Validators

Custom validators defined per attribute (as opposed to the custom validators defined in the model’s options) now run when the attribute’s value is null and allowNull is true (while previously they didn’t run and the validation succeeded immediately). To avoid problems when upgrading, please check all your custom validators defined per attribute, where allowNull is true, and make sure all these validators behave correctly when the value is null. See #9143.

Attributes

Model.attributes now removed, use Model.rawAttributes#5320

NotePlease don’t confuse this with options.attributes, they are still valid

Paranoid Mode

With v5 if deletedAt is set, record will be considered as deleted. paranoid option will only use deletedAt as flag. #8496

Model.bulkCreate

updateOnDuplicate option which used to accept boolean and array, now only accepts non-empty array of attributes. #9288

Underscored Mode

Implementation of Model.options.underscored is changed. You can find full specifications here.

Main outline

  1. Both underscoredAll and underscored options are merged into single underscored option
  2. All attributes are now generated with camelcase naming by default. With the underscored option set to true, the field option for attributes will be set as underscored version of attribute name.
  3. underscored will control all attributes including timestamps, version and foreign keys. It will not affect any attribute which already specifies the field option.

#9304

Removed aliases

Many model based aliases has been removed #9372

Download