This type allows using Op.or
, Op.and
, and Op.not
recursively around another type.
It also supports using a plain Array as an alias for Op.and
. (unlike AllowNotOrAndRecursive).
Example of plain-array treated as Op.and
:
User.findAll({ where: [{ id: 1 }, { id: 2 }] });
Meant to be used by WhereOptions.
Returns the creation attributes of a given Model.
This returns the Attributes of a Model that have already been defined, it does not build them. If you need to build them, use InferAttributes.
The createAssociation mixin applied to models with Model.belongsTo. An example of usage is as follows:
User.belongsTo(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRole...
// setRole...
createRole: Sequelize.BelongsToCreateAssociationMixin<RoleAttributes>;
}
The getAssociation mixin applied to models with Model.belongsTo. An example of usage is as follows:
User.belongsTo(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttrib>, UserAttrib {
getRole: Sequelize.BelongsToGetAssociationMixin<RoleInstance>;
// setRole...
// createRole...
}
The addAssociation mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
addRole: Sequelize.BelongsToManyAddAssociationMixin<RoleInstance, RoleId, UserRoleAttributes>;
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The addAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
addRoles: Sequelize.BelongsToManyAddAssociationsMixin<RoleInstance, RoleId, UserRoleAttributes>;
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The countAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
countRoles: Sequelize.BelongsToManyCountAssociationsMixin;
}
The createAssociation mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
createRole: Sequelize.BelongsToManyCreateAssociationMixin<RoleAttributes, UserRoleAttributes>;
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The getAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
getRoles: Sequelize.BelongsToManyGetAssociationsMixin<RoleInstance>;
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The hasAssociation mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
hasRole: Sequelize.BelongsToManyHasAssociationMixin<RoleInstance, RoleId>;
// hasRoles...
// countRoles...
}
The removeAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles
// hasRole...
hasRoles: Sequelize.BelongsToManyHasAssociationsMixin<RoleInstance, RoleId>;
// countRoles...
}
The removeAssociation mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
removeRole: Sequelize.BelongsToManyRemoveAssociationMixin<RoleInstance, RoleId>;
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The removeAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
removeRoles: Sequelize.BelongsToManyRemoveAssociationsMixin<RoleInstance, RoleId>;
// hasRole...
// hasRoles...
// countRoles...
}
The setAssociations mixin applied to models with Model.belongsToMany. An example of usage is as follows:
User.belongsToMany(Role, { through: UserRole });
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
setRoles: Sequelize.BelongsToManySetAssociationsMixin<RoleInstance, RoleId, UserRoleAttributes>;
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The setAssociation mixin applied to models with Model.belongsTo. An example of usage is as follows:
User.belongsTo(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRole...
setRole: Sequelize.BelongsToSetAssociationMixin<RoleInstance, RoleId>;
// createRole...
}
Internal type - prone to changes. Do not export.
Options for Model.count when GROUP BY is used
Returns the creation attributes of a given Model.
This returns the Creation Attributes of a Model, it does not build them. If you need to build them, use InferCreationAttributes.
This is a Branded Type. You can use it to tag attributes that can be ommited during Model Creation.
For use with InferCreationAttributes.
Represents acceptable Dynamic values.
Dynamic values, as opposed to StaticValues. i.e. column references, functions, etc...
This is a Branded Type. You can use it to tag fields from your class that are foreign keys. They will become optional in Model.init (as foreign keys are added by association methods, like Model.hasMany.
The addAssociation mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
addRole: Sequelize.HasManyAddAssociationMixin<RoleInstance, RoleId>;
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The addAssociations mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
addRoles: Sequelize.HasManyAddAssociationsMixin<RoleInstance, RoleId>;
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The countAssociations mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
countRoles: Sequelize.HasManyCountAssociationsMixin;
}
The createAssociation mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
createRole: Sequelize.HasManyCreateAssociationMixin<RoleAttributes>;
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The getAssociations mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
getRoles: Sequelize.HasManyGetAssociationsMixin<RoleInstance>;
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The hasAssociation mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
hasRole: Sequelize.HasManyHasAssociationMixin<RoleInstance, RoleId>;
// hasRoles...
// countRoles...
}
The removeAssociations mixin applied to models with hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles
// hasRole...
hasRoles: Sequelize.HasManyHasAssociationsMixin<RoleInstance, RoleId>;
// countRoles...
}
This method returns true if all provided targets are associated to the source model, and false if any of the provided targets are not.
The removeAssociation mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
removeRole: Sequelize.HasManyRemoveAssociationMixin<RoleInstance, RoleId>;
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The removeAssociations mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
// setRoles...
// addRoles...
// addRole...
// createRole...
// removeRole...
removeRoles: Sequelize.HasManyRemoveAssociationsMixin<RoleInstance, RoleId>;
// hasRole...
// hasRoles...
// countRoles...
}
The setAssociations mixin applied to models with Model.hasMany. An example of usage is as follows:
User.hasMany(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRoles...
setRoles: Sequelize.HasManySetAssociationsMixin<RoleInstance, RoleId>;
// addRoles...
// addRole...
// createRole...
// removeRole...
// removeRoles...
// hasRole...
// hasRoles...
// countRoles...
}
The createAssociation mixin applied to models with Model.hasOne. An example of usage is as follows:
User.hasOne(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRole...
// setRole...
createRole: Sequelize.HasOneCreateAssociationMixin<RoleAttributes>;
}
The getAssociation mixin applied to models with Model.hasOne. An example of usage is as follows:
User.hasOne(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttrib>, UserAttrib {
getRole: Sequelize.HasOneGetAssociationMixin<RoleInstance>;
// setRole...
// createRole...
}
The setAssociation mixin applied to models with Model.hasOne. An example of usage is as follows:
User.hasOne(Role);
interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
// getRole...
setRole: Sequelize.HasOneSetAssociationMixin<RoleInstance, RoleId>;
// createRole...
}
Possible types for primary keys
Options for eager-loading associated models.
The association can be specified in different ways:
{ include: 'associationName' }
(recommended){ include: MyModel.associations['associationName'] }
{ include: Model1 }
{ include: { model: Model1, as: 'Alias' } }
You can also eagerly load all associations using { include: { all: true } }
(not recommended outside of debugging)
Utility type to extract Attributes of a given Model class.
It returns all instance properties defined in the Model, except:
It cannot detect whether something is a getter or not, you should use the Excluded
parameter to exclude getter & setters from the attribute list.
Option bag for InferAttributes.
Utility type to extract Creation Attributes of a given Model class.
Works like InferAttributes, but fields that are tagged using CreationOptional will be optional.
Type will be true is T is branded with Brand, false otherwise
Interface for Attributes provided for all columns in a model
This is a Branded Type. You can use it to tag fields from your class that are NOT attributes. They will be ignored by InferAttributes and InferCreationAttributes
Internal type - prone to changes. Do not export.
Type helper for making certain fields of an object optional. This is helpful
for creating the CreationAttributes
from your Attributes
for a Model.
Please note if this is used the aliased property will not be available on the model instance
as a property but only via instance.get('alias')
.
This type represents the output of the RANGE data type.
Represents acceptable Static values.
Static values, as opposed to DynamicValues. i.e. booleans, strings, etc...
A pojo of values to update.
Used by Model.update
A hash of attributes to describe your search.
Possible key values:
An attribute name: { id: 1 }
A nested attribute: { '$projects.id$': 1 }
A JSON key: { 'object.key': 1 }
A cast: { 'id::integer': 1 }
A combination of the above: { '$join.attribute$.json.path::integer': 1 }
Types that can be compared to an attribute in a WHERE context.
The type accepted by every where
option
Internal type - prone to changes. Do not export.
An array of type
, e.g. DataTypes.ARRAY(DataTypes.DECIMAL)
. Only available in postgres.
A 64 bit integer.
Available properties: UNSIGNED
, ZEROFILL
Binary storage. Available lengths: tiny
, medium
, long
A boolean / tinyint column, depending on dialect
A fixed length string. Default length 255
Case-insensitive text
Dummy Symbol used as branding by CreationOptional.
Do not export, Do not use.
A datetime column
A date only column
Decimal number. Accepts one or two arguments for precision
Floating point number (8-byte precision). Accepts one or two arguments for precision
An enumeration. DataTypes.ENUM('value', 'another value')
.
Floating point number (4-byte precision). Accepts one or two arguments for precision
Dummy Symbol used as branding by ForeignKey.
Do not export, Do not use.
A geography datatype represents two dimensional spacial objects in an elliptic coord system.
A geometry datatype represents two dimensional spacial objects.
A key / value column. Only available in postgres.
A 32 bit integer.
A JSON string column. Only available in postgres.
A pre-processed JSON data column. Only available in postgres.
A 24 bit integer.
A default value of the current timestamp
Dummy Symbol used as branding by NonAttribute.
Do not export, Do not use.
Range types are data types representing a range of values of some element type (called the range's subtype). Only available in postgres.
See Postgres documentation for more details
Floating point number (4-byte precision). Accepts one or two arguments for precision
A 16 bit integer.
A variable length string. Default length 255
An (un)limited length text column. Available lengths: tiny
, medium
, long
A time column
A 8 bit integer.
Full text search vector. Only available in postgres.
A column storing a unique universal identifier. Use with UUIDV1
or UUIDV4
for default values.
A default unique universal identifier generated following the UUID v1 standard
A default unique universal identifier generated following the UUID v4 standard
A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model that is returned to the user but not stored in the DB.
You could also use it to validate a value before permuting and storing it. Checking password length before hashing it for example:
class User extends Model {}
User.init({
password_hash: DataTypes.STRING,
password: {
type: DataTypes.VIRTUAL,
set (val) {
this.setDataValue('password', val); // Remember to set the data value, otherwise it won't be validated
this.setDataValue('password_hash', this.salt + val);
},
validate: {
isLongEnough (val) {
if (val.length < 7) {
throw new Error("Please choose a longer password")
}
}
}
}
}, { sequelize });
VIRTUAL also takes a return type and dependency fields as arguments
If a virtual attribute is present in attributes
it will automatically pull in the extra fields as well.
Return type is mostly useful for setups that rely on types like GraphQL.
{
active: {
type: new DataTypes.VIRTUAL(DataTypes.BOOLEAN, ['createdAt']),
get() {
return this.get('createdAt') > Date.now() - (7 * 24 * 60 * 60 * 1000)
}
}
}
In the above code the password is stored plainly in the password field so it can be validated, but is never stored in the DB.
An AND query
Each argument will be joined by AND
Creates a object representing a call to the cast function.
The value to cast
The type to cast it to
Creates a object representing a column in the DB. This is often useful in conjunction with
sequelize.fn
, since raw string arguments to fn will be escaped.
The name of the column
Creates a object representing a database function. This can be used in search queries, both in where and
order parts, and as default values in column definitions. If you want to refer to columns in your
function, you should use sequelize.col
, so that the columns are properly interpreted as columns and
not a strings.
Convert a user's username to upper case
instance.update({
username: self.sequelize.fn('upper', self.sequelize.col('username'))
})
The function you want to call
All further arguments will be passed as arguments to the function
Returns true if the value is a model subclass.
The value whose type will be checked
Returns true if a & b are the same initial model, ignoring variants created by Model.withSchema, Model.withScope, and the like.
The difference with doing a === b
is that this method will also
return true if one of the models is scoped, or a variant with a different schema.
Creates an object representing nested where conditions for postgres's json data-type.
A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax.
An optional value to compare against. Produces a string of the form "<json path> = '<value>'".
Creates a object representing a literal, i.e. something that will not be escaped.
An OR query
Each argument will be joined by OR
A way of specifying "attr = condition".
Can be used as a replacement for the POJO syntax (e.g. where: { name: 'Lily' }
) when you need to compare a column that the POJO syntax cannot represent.
The left side of the comparison.
The comparison operator to use. If unspecified, defaults to {@link Op.eq}.
The right side of the comparison. Its value depends on the used operator. See WhereOperators for information about what value is valid for each operator.
Generated using TypeDoc
This type allows using
Op.or
,Op.and
, andOp.not
recursively around another type. Unlike AllowNotOrAndWithImplicitAndArrayRecursive, it does not allow the 'implicit AND Array'.Example of plain-array NOT treated as Op.and: User.findAll({ where: { id: [1, 2] } });
Meant to be used by WhereAttributeHashValue.