API Reference Source

Upgrade to v5

Sequelize v5 is the next major release after v4

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.

operators-security

With v5

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 [email protected]. 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

Note: Please 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

Removed in v5 Official Alternative
insertOrUpdate upsert
find findOne
findAndCount findAndCountAll
findOrInitialize findOrBuild
updateAttributes update
findById, findByPrimary findByPk
all findAll
hook addHook

Datatypes

Range

Now supports only one standard format [{ value: 1, inclusive: true }, { value: 20, inclusive: false }] #9364

Case insensitive text

Added support for CITEXT for Postgres and SQLite

Removed

NONE type has been removed, use VIRTUAL instead

Hooks

Removed aliases

Hooks aliases has been removed #9372

Removed in v5 Official Alternative
[after,before]BulkDelete [after,before]BulkDestroy
[after,before]Delete [after,before]Destroy
beforeConnection beforeConnect

Sequelize

Removed aliases

Prototype references for many constants, objects and classes has been removed #9372

Removed in v5 Official Alternative
Sequelize.prototype.Utils Sequelize.Utils
Sequelize.prototype.Promise Sequelize.Promise
Sequelize.prototype.TableHints Sequelize.TableHints
Sequelize.prototype.Op Sequelize.Op
Sequelize.prototype.Transaction Sequelize.Transaction
Sequelize.prototype.Model Sequelize.Model
Sequelize.prototype.Deferrable Sequelize.Deferrable
Sequelize.prototype.Error Sequelize.Error
Sequelize.prototype[error] Sequelize[error]
import Sequelize from 'sequelize';
const sequelize = new Sequelize('postgres://user:[email protected]:mydb');

/**
 * In v4 you can do this
 */
console.log(sequelize.Op === Sequelize.Op) // logs `true`
console.log(sequelize.UniqueConstraintError === Sequelize.UniqueConstraintError) // logs `true`

Model.findAll({
  where: {
    [sequelize.Op.and]: [ // Using sequelize.Op or Sequelize.Op interchangeably
      {
        name: "Abc"
      },
      {
        age: {
          [Sequelize.Op.gte]: 18
        }
      }
    ]
  }
}).catch(sequelize.ConnectionError, () => {
  console.error('Something wrong with connection?');
});

/**
 * In v5 aliases has been removed from Sequelize prototype
 * You should use Sequelize directly to access Op, Errors etc
 */

Model.findAll({
  where: {
    [Sequelize.Op.and]: [ // Don't use sequelize.Op, use Sequelize.Op instead
      {
        name: "Abc"
      },
      {
        age: {
          [Sequelize.Op.gte]: 18
        }
      }
    ]
  }
}).catch(Sequelize.ConnectionError, () => {
  console.error('Something wrong with connection?');
});

Query Interface

Others

Dialect Specific

MSSQL

dialectOptions: {
  authentication: {
    domain: 'my-domain'
  },
  options: {
    requestTimeout: 60000,
    cryptoCredentialsDetails: {
      ciphers: "RC4-MD5"
    }
  }
}

MySQL

MariaDB

Packages

Changelog

5.0.0-beta.17

5.0.0-beta.16

5.0.0-beta.15

5.0.0-beta.14

5.0.0-beta.13

5.0.0-beta.12

5.0.0-beta.11

5.0.0-beta.10

5.0.0-beta.9

5.0.0-beta.8

5.0.0-beta.7

5.0.0-beta.6

5.0.0-beta.5

5.0.0-beta.4

5.0.0-beta.3

5.0.0-beta.2

5.0.0-beta.1

5.0.0-beta