API Reference Source
Docs v6

Variable

Static Public Summary
public

A convenience class holding commonly used data types.

public

Deferrable: {"INITIALLY_DEFERRED": *, "INITIALLY_IMMEDIATE": *, "NOT": *, "SET_DEFERRED": *, "SET_IMMEDIATE": *}

A collection of properties related to deferrable constraints.

public

An enum of index hints to be used in mysql for querying with index hints

public

An enum of query types used by sequelize.query

public

An enum of table hints to be used in mssql for querying with table hints

public

An enum that defines valid ValidationErrorItem origin values

public

An enum that is used internally by the ValidationErrorItem class that maps current type strings (as given to ValidationErrorItem.constructor()) to our new origin values.

Static Public

public DataTypes: * source

A convenience class holding commonly used data types. The data types are used when defining a new model using Sequelize.define, like this:

sequelize.define('model', {
  column: DataTypes.INTEGER
})

When defining a model you can just as easily pass a string as type, but often using the types defined here is beneficial. For example, using DataTypes.BLOB, mean that that column will be returned as an instance of Buffer when being fetched by sequelize.

To provide a length for the data type, you can invoke it like a function: INTEGER(2)

Some data types have special properties that can be accessed in order to change the data type. For example, to get an unsigned integer with zerofill you can do DataTypes.INTEGER.UNSIGNED.ZEROFILL. The order you access the properties in do not matter, so DataTypes.INTEGER.ZEROFILL.UNSIGNED is fine as well.

  • All number types (INTEGER, BIGINT, FLOAT, DOUBLE, REAL, DECIMAL) expose the properties UNSIGNED and ZEROFILL
  • The CHAR and STRING types expose the BINARY property

Three of the values provided here (NOW, UUIDV1 and UUIDV4) are special default values, that should not be used to define types. Instead they are used as shorthands for defining default values. For example, to get a uuid field with a default value generated following v1 of the UUID standard:

sequelize.define('model', {
  uuid: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV1,
    primaryKey: true
  }
})

There may be times when you want to generate your own UUID conforming to some other algorithm. This is accomplished using the defaultValue property as well, but instead of specifying one of the supplied UUID types, you return a value from a function.

sequelize.define('model', {
  uuid: {
    type: DataTypes.UUID,
    defaultValue: function() {
      return generateMyId()
    },
    primaryKey: true
  }
})

public Deferrable: {"INITIALLY_DEFERRED": *, "INITIALLY_IMMEDIATE": *, "NOT": *, "SET_DEFERRED": *, "SET_IMMEDIATE": *} source

A collection of properties related to deferrable constraints. It can be used to make foreign key constraints deferrable and to set the constraints within a transaction. This is only supported in PostgreSQL.

The foreign keys can be configured like this. It will create a foreign key that will check the constraints immediately when the data was inserted.

sequelize.define('Model', {
  foreign_id: {
    type: Sequelize.INTEGER,
    references: {
      model: OtherModel,
      key: 'id',
      deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
    }
  }
});

The constraints can be configured in a transaction like this. It will trigger a query once the transaction has been started and set the constraints to be checked at the very end of the transaction.

sequelize.transaction({
  deferrable: Sequelize.Deferrable.SET_DEFERRED
});

Properties:

NameTypeAttributeDescription
INITIALLY_DEFERRED *

Use when declaring a constraint. Allow and enable by default this constraint's checks to be deferred at the end of transactions.

INITIALLY_IMMEDIATE *

Use when declaring a constraint. Allow the constraint's checks to be deferred at the end of transactions.

NOT *

Use when declaring a constraint. Set the constraint to not deferred. This is the default in PostgreSQL and makes it impossible to dynamically defer the constraints within a transaction.

SET_DEFERRED *

Use when declaring a transaction. Defer the deferrable checks involved in this transaction at commit.

SET_IMMEDIATE *

Use when declaring a transaction. Execute the deferrable checks involved in this transaction immediately.

public IndexHints: * source

An enum of index hints to be used in mysql for querying with index hints

Properties:

NameTypeAttributeDescription
USE *
FORCE *
IGNORE *

public QueryTypes: * source

An enum of query types used by sequelize.query

Properties:

NameTypeAttributeDescription
SELECT *
INSERT *
UPDATE *
BULKUPDATE *
BULKDELETE *
DELETE *
UPSERT *
VERSION *
SHOWTABLES *
SHOWINDEXES *
DESCRIBE *
RAW *
FOREIGNKEYS *
SHOWCONSTRAINTS *

See:

public TableHints: * source

An enum of table hints to be used in mssql for querying with table hints

Properties:

NameTypeAttributeDescription
NOLOCK *
READUNCOMMITTED *
UPDLOCK *
REPEATABLEREAD *
SERIALIZABLE *
READCOMMITTED *
TABLOCK *
TABLOCKX *
PAGLOCK *
ROWLOCK *
NOWAIT *
READPAST *
XLOCK *
SNAPSHOT *
NOEXPAND *

public ValidationErrorItemOrigin: * source

An enum that defines valid ValidationErrorItem origin values

public ValidationErrorItemType: * source

An enum that is used internally by the ValidationErrorItem class that maps current type strings (as given to ValidationErrorItem.constructor()) to our new origin values.