Options
All
  • Public
  • Public/Protected
  • All
Menu

@sequelize/core

Index

References

Namespaces

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

References

Renames and re-exports Error
Renames and re-exports Sequelize
Re-exports useInflection

Type Aliases

AfterAssociateEventData: BeforeAssociateEventData & { association: Association }
AllowAnyAll<T>: T | { [all]: Exclude<T, InvalidInSqlArray>[] | Literal | { [values]: (T | DynamicValues<T>)[] } } | { [any]: Exclude<T, InvalidInSqlArray>[] | Literal | { [values]: (T | DynamicValues<T>)[] } }

Type Parameters

  • T

AllowNotOrAndRecursive<T>: T | { [or]: AllowArray<AllowNotOrAndRecursive<T>> } | { [and]: AllowArray<AllowNotOrAndRecursive<T>> } | { [not]: AllowNotOrAndRecursive<T> }

This type allows using Op.or, Op.and, and Op.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.

Type Parameters

  • T

AllowNotOrAndWithImplicitAndArrayRecursive<T>: AllowArray<T | { [or]: AllowArray<AllowNotOrAndWithImplicitAndArrayRecursive<T>> } | { [and]: AllowArray<AllowNotOrAndWithImplicitAndArrayRecursive<T>> } | { [not]: AllowNotOrAndWithImplicitAndArrayRecursive<T> }>

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.

Type Parameters

  • T

AttributeNames<M>: Extract<keyof M["_attributes"], string>

Type Parameters

Attributes<M>: M["_attributes"]

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.

example
function getValue<M extends Model>(modelClass: ModelStatic<M>, attribute: keyof Attributes<M>) {}

Type Parameters

BeforeAssociateEventData: { sequelize: Sequelize; source: ModelStatic<Model>; target: ModelStatic<Model>; type: Class<Association> }

Type declaration

BelongsToCreateAssociationMixin<T>: ((values?: CreationAttributes<T>, options?: BelongsToCreateAssociationMixinOptions<T>) => Promise<T>)

Type Parameters

Type declaration

BelongsToGetAssociationMixin<T>: ((options?: BelongsToGetAssociationMixinOptions<T>) => Promise<T | null>)

Type Parameters

Type declaration

    • The getAssociation mixin applied to models with belongsTo. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare getRole: BelongsToGetAssociationMixin<Role>;
      }

      User.belongsTo(Role);
      see

      Model.belongsTo

      Parameters

      Returns Promise<T | null>

BelongsToManyAddAssociationMixin<T, TModelPrimaryKey>: ((newAssociation?: T | TModelPrimaryKey, options?: BelongsToManyAddAssociationMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The addAssociation mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare addRole: BelongsToManyAddAssociationMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<void>

BelongsToManyAddAssociationsMixin<T, TModelPrimaryKey>: ((newAssociations?: (T | TModelPrimaryKey)[], options?: BelongsToManyAddAssociationsMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The addAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare addRoles: BelongsToManyAddAssociationsMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<void>

BelongsToManyCountAssociationsMixin<T>: ((options?: BelongsToManyCountAssociationsMixinOptions<T>) => Promise<number>)

Type Parameters

Type declaration

    • The countAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare countRoles: Sequelize.BelongsToManyCountAssociationsMixin;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<number>

BelongsToManyCreateAssociationMixin<T>: ((values?: CreationAttributes<T>, options?: BelongsToManyCreateAssociationMixinOptions<T>) => Promise<T>)

Type Parameters

Type declaration

BelongsToManyGetAssociationsMixin<T>: ((options?: BelongsToManyGetAssociationsMixinOptions<T>) => Promise<T[]>)

Type Parameters

Type declaration

    • The getAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare getRoles: BelongsToManyGetAssociationsMixin<Role>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<T[]>

BelongsToManyHasAssociationMixin<TModel, TModelPrimaryKey>: ((target: TModel | TModelPrimaryKey, options?: BelongsToManyHasAssociationMixinOptions<TModel>) => Promise<boolean>)

Type Parameters

  • TModel extends Model

  • TModelPrimaryKey

Type declaration

    • The hasAssociation mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare hasRole: BelongsToManyHasAssociationMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<boolean>

BelongsToManyHasAssociationsMixin<TModel, TModelPrimaryKey>: ((targets: (TModel | TModelPrimaryKey)[], options?: BelongsToManyHasAssociationsMixinOptions<TModel>) => Promise<boolean>)

Type Parameters

  • TModel extends Model

  • TModelPrimaryKey

Type declaration

    • The removeAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare hasRoles: BelongsToManyHasAssociationsMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<boolean>

BelongsToManyRemoveAssociationMixin<TModel, TModelPrimaryKey>: ((oldAssociated?: TModel | TModelPrimaryKey, options?: BelongsToManyRemoveAssociationMixinOptions) => Promise<void>)

Type Parameters

  • TModel

  • TModelPrimaryKey

Type declaration

    • The removeAssociation mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare removeRole: BelongsToManyRemoveAssociationMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<void>

BelongsToManyRemoveAssociationsMixin<TModel, TModelPrimaryKey>: ((associationsToRemove?: (TModel | TModelPrimaryKey)[], options?: BelongsToManyRemoveAssociationsMixinOptions) => Promise<void>)

Type Parameters

  • TModel

  • TModelPrimaryKey

Type declaration

    • The removeAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare removeRoles: BelongsToManyRemoveAssociationsMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<void>

BelongsToManySetAssociationsMixin<TModel, TModelPrimaryKey>: ((newAssociations?: (TModel | TModelPrimaryKey)[], options?: BelongsToManySetAssociationsMixinOptions<TModel>) => Promise<void>)

Type Parameters

  • TModel extends Model

  • TModelPrimaryKey

Type declaration

    • The setAssociations mixin applied to models with belongsToMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare setRoles: BelongsToManySetAssociationsMixin<Role, Role['id']>;
      }

      User.belongsToMany(Role, { through: UserRole });
      see

      Model.belongsToMany

      Parameters

      Returns Promise<void>

BelongsToSetAssociationMixin<T, TargetKeyType>: ((newAssociation?: T | TargetKeyType, options?: BelongsToSetAssociationMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TargetKeyType

    The type of the attribute that the foreign key references.

Type declaration

    • The setAssociation mixin applied to models with belongsTo. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare setRole: BelongsToSetAssociationMixin<Role, Role['id']>;
      }

      User.belongsTo(Role);
      see

      Model.belongsTo

      Parameters

      Returns Promise<void>

BindOrReplacements: {} | unknown[]
BlobSize: "tiny" | "medium" | "long"
BrandedKeysOf<T, Brand>: { [ P in keyof T]-?: IsBranded<T[P], Brand> extends true ? P : never }[keyof T]

Type Parameters

  • T

  • Brand extends symbol

BuiltModelName: Required<ModelNameOptions>
BuiltModelOptions<M>: Omit<InitOptions<M>, "name"> & { name: BuiltModelName }

Type Parameters

ColumnReference: Col | { [col]: string }

Internal type - prone to changes. Do not export.

ContinuationLocalStorageNamespace: { get: any; set: any }

Type declaration

  • get:function
    • get(key: string): unknown
    • Parameters

      • key: string

      Returns unknown

  • set:function
    • set(key: string, value: unknown): void
    • Parameters

      • key: string
      • value: unknown

      Returns void

CountWithOptions<TAttributes>: SetRequired<CountOptions<TAttributes>, "group">

Options for Model.count when GROUP BY is used

Type Parameters

  • TAttributes = any

CreationAttributes<M>: MakeNullishOptional<M["_creationAttributes"]>

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.

example
function buildModel<M extends Model>(modelClass: ModelStatic<M>, attributes: CreationAttributes<M>) {}

Type Parameters

CreationOptional<T>: T extends null | undefined ? T : T & { [CreationAttributeBrand]?: true }

This is a Branded Type. You can use it to tag attributes that can be ommited during Model Creation.

Type Parameters

  • T

Dialect: "mysql" | "postgres" | "sqlite" | "mariadb" | "mssql" | "db2" | "snowflake" | "ibmi"
DynamicValues<AcceptableValues>: Literal | ColumnReference | Fn | Cast | (AcceptableValues extends boolean ? Where : never)

Represents acceptable Dynamic values.

Dynamic values, as opposed to StaticValues. i.e. column references, functions, etc...

Type Parameters

  • AcceptableValues

EmptyRange: []
FieldMap: {}

Type declaration

  • [key: string]: string
FindAttributeOptions: (string | ProjectionAlias | Literal)[] | { exclude: string[]; include?: (string | ProjectionAlias)[] } | { exclude?: string[]; include: (string | ProjectionAlias)[] }
ForeignKey<T>: T extends null | undefined ? T : T & { [ForeignKeyBrand]?: true }

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.

Type Parameters

  • T

GroupOption: AllowArray<string | Fn | Col | Literal>
HasManyAddAssociationMixin<T, TModelPrimaryKey>: ((newAssociation?: T | TModelPrimaryKey, options?: HasManyAddAssociationMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The addAssociation mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare addRole: HasManyAddAssociationMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<void>

HasManyAddAssociationsMixin<T, TModelPrimaryKey>: ((newAssociations?: (T | TModelPrimaryKey)[], options?: HasManyAddAssociationsMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The addAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare addRoles: HasManyAddAssociationsMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<void>

HasManyCountAssociationsMixin<T>: ((options?: HasManyCountAssociationsMixinOptions<T>) => Promise<number>)

Type Parameters

Type declaration

    • The countAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare countRoles: HasManyCountAssociationsMixin<Role>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<number>

HasManyCreateAssociationMixin<TModel, TForeignKey, TScope>: ((values?: Omit<CreationAttributes<TModel>, TForeignKey | TScope>, options?: HasManyCreateAssociationMixinOptions<TModel>) => Promise<TModel>)

Type Parameters

Type declaration

    • The createAssociation mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare createRole: HasManyCreateAssociationMixin<Role>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<TModel>

HasManyGetAssociationsMixin<T>: ((options?: HasManyGetAssociationsMixinOptions<T>) => Promise<T[]>)

Type Parameters

Type declaration

    • The getAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare getRoles: HasManyGetAssociationsMixin<Role>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<T[]>

HasManyHasAssociationMixin<TModel, TModelPrimaryKey>: ((target: TModel | TModelPrimaryKey, options?: HasManyHasAssociationMixinOptions<TModel>) => Promise<boolean>)

Type Parameters

  • TModel extends Model

  • TModelPrimaryKey

Type declaration

    • The hasAssociation mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare hasRole: HasManyHasAssociationMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<boolean>

HasManyHasAssociationsMixin<TModel, TModelPrimaryKey>: ((targets: (TModel | TModelPrimaryKey)[], options?: HasManyHasAssociationsMixinOptions<TModel>) => Promise<boolean>)

Type Parameters

  • TModel extends Model

  • TModelPrimaryKey

Type declaration

    • The removeAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare hasRoles: HasManyHasAssociationsMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<boolean>

HasManyRemoveAssociationMixin<T, TModelPrimaryKey>: ((oldAssociated?: T | TModelPrimaryKey, options?: HasManyRemoveAssociationMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The removeAssociation mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare removeRole: HasManyRemoveAssociationMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<void>

HasManyRemoveAssociationsMixin<T, TModelPrimaryKey>: ((oldAssociateds?: (T | TModelPrimaryKey)[], options?: HasManyRemoveAssociationsMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The removeAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare removeRoles: HasManyRemoveAssociationsMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<void>

HasManySetAssociationsMixin<T, TModelPrimaryKey>: ((newAssociations?: (T | TModelPrimaryKey)[], options?: HasManySetAssociationsMixinOptions<T>) => Promise<void>)

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The setAssociations mixin applied to models with hasMany. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare setRoles: HasManySetAssociationsMixin<Role, Role['id']>;
      }

      User.hasMany(Role);
      see

      Model.hasMany

      Parameters

      Returns Promise<void>

HasOneCreateAssociationMixin<T>: ((values?: CreationAttributes<T>, options?: HasOneCreateAssociationMixinOptions<T>) => Promise<T>)

Type Parameters

Type declaration

HasOneGetAssociationMixin<T>: ((options?: HasOneGetAssociationMixinOptions<T>) => Promise<T | null>)

Type Parameters

Type declaration

    • The getAssociation mixin applied to models with hasOne. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare getRole: HasOneGetAssociationMixin<Role>;
      }

      User.hasOne(Role);
      see

      Model.hasOne

      Parameters

      Returns Promise<T | null>

      The associated model, or null if no model is associated. HasOne associations are always nullable because the foreign key is on the target model.

HasOneSetAssociationMixin<T, TModelPrimaryKey>: { (newAssociation: null, options?: HasOneSetAssociationMixinOptions<T>): Promise<null>; (newAssociation: T | TModelPrimaryKey, options?: HasOneSetAssociationMixinOptions<T>): Promise<T> }

Type Parameters

  • T extends Model

  • TModelPrimaryKey

Type declaration

    • The setAssociation mixin applied to models with hasOne. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare setRole: HasOneSetAssociationMixin<Role, Role['id']>;
      }

      User.hasOne(Role);
      see

      Model.hasOne

      Parameters

      Returns Promise<null>

    • The setAssociation mixin applied to models with hasOne. An example of usage is as follows:

      class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
      declare setRole: HasOneSetAssociationMixin<Role, Role['id']>;
      }

      User.hasOne(Role);
      see

      Model.hasOne

      Parameters

      Returns Promise<T>

Identifier: number | bigint | string | Buffer

Possible types for primary keys

Includeable: ModelStatic | Association | IncludeOptions | { all: true; nested?: true } | string

Options for eager-loading associated models.

The association can be specified in different ways:

  • Using the name of the association: { include: 'associationName' } (recommended)
  • Using a reference to the association: { include: MyModel.associations['associationName'] }
  • Using the model to eager-load (an association must still be defined!): { include: Model1 }
    • if the association with that model has an alias, you need to specify it too: { include: { model: Model1, as: 'Alias' } }

You can also eagerly load all associations using { include: { all: true } } (not recommended outside of debugging)

IndexMethod: "BTREE" | "HASH" | "GIST" | "SPGIST" | "GIN" | "BRIN" | string
IndexType: "UNIQUE" | "FULLTEXT" | "SPATIAL"
InferAttributes<M, Options>: { [ Key in keyof M as InternalInferAttributeKeysFromFields<M, Key, Options>]: M[Key] }

Utility type to extract Attributes of a given Model class.

It returns all instance properties defined in the Model, except:

  • those inherited from Model (intermediate inheritance works),
  • the ones whose type is a function,
  • the ones manually excluded using the second parameter.
  • the ones branded using NonAttribute

It cannot detect whether something is a getter or not, you should use the Excluded parameter to exclude getter & setters from the attribute list.

example
// listed attributes will be 'id' & 'firstName'.
class User extends Model<InferAttributes<User>> {
id: number;
firstName: string;
}
example
// listed attributes will be 'id' & 'firstName'.
// we're excluding the `name` getter & `projects` attribute using the `omit` option.
class User extends Model<InferAttributes<User, { omit: 'name' | 'projects' }>> {
id: number;
firstName: string;

// this is a getter, not an attribute. It should not be listed in attributes.
get name(): string { return this.firstName; }
// this is an association, it should not be listed in attributes
projects?: Project[];
}
example
// listed attributes will be 'id' & 'firstName'.
// we're excluding the `name` getter & `test` attribute using the `NonAttribute` branded type.
class User extends Model<InferAttributes<User>> {
id: number;
firstName: string;

// this is a getter, not an attribute. It should not be listed in attributes.
get name(): NonAttribute<string> { return this.firstName; }
// this is an association, it should not be listed in attributes
projects?: NonAttribute<Project[]>;
}

Type Parameters

InferAttributesOptions<Excluded>: { omit?: Excluded }

Option bag for InferAttributes.

  • omit: properties to not treat as Attributes.

Type Parameters

  • Excluded

Type declaration

  • Optional omit?: Excluded
InferCreationAttributes<M, Options>: { [ Key in keyof M as InternalInferAttributeKeysFromFields<M, Key, Options>]: IsBranded<M[Key], typeof CreationAttributeBrand> extends true ? M[Key] | undefined : M[Key] }

Utility type to extract Creation Attributes of a given Model class.

Works like InferAttributes, but fields that are tagged using CreationOptional will be optional.

example
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
// this attribute is optional in Model#create
declare id: CreationOptional<number>;

// this attribute is mandatory in Model#create
declare name: string;
}

Type Parameters

InternalInferAttributeKeysFromFields<M, Key, Options>: M[Key] extends AnyFunction ? never : Key extends keyof Model ? never : IsBranded<M[Key], typeof NonAttributeBrand> extends true ? never : Options["omit"] extends string ? Key extends Options["omit"] ? never : Key : Key

Type Parameters

InvalidInSqlArray: ColumnReference | Fn | Cast | null | Literal
IsBranded<T, Brand>: keyof NonNullable<T> extends keyof Omit<NonNullable<T>, Brand> ? false : true

Type will be true is T is branded with Brand, false otherwise

Type Parameters

  • T

  • Brand extends symbol

ModelAttributes<M, TAttributes>: { [ name in keyof TAttributes]: DataTypes.DataType | ModelAttributeColumnOptions<M> }

Interface for Attributes provided for all columns in a model

Type Parameters

ModelDefined<S, T>: ModelStatic<Model<S, T>>

Type Parameters

  • S

  • T

ModelStatic<M>: OmitConstructors<typeof Model> & {}

Type Parameters

MultiAssociationAccessors: { add: string; addMultiple: string; count: string; create: string; get: string; hasAll: string; hasSingle: string; remove: string; removeMultiple: string; set: string }

Type declaration

  • add: string
  • addMultiple: string
  • count: string
  • create: string
  • get: string
  • hasAll: string
  • hasSingle: string
  • remove: string
  • removeMultiple: string
  • set: string
NonAttribute<T>: T extends null | undefined ? T : T & { [NonAttributeBrand]?: true }

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

Type Parameters

  • T

NormalizedAssociationOptions<ForeignKey>: NormalizeBaseAssociationOptions<AssociationOptions<ForeignKey>>

Type Parameters

  • ForeignKey extends string

NormalizedBelongsToOptions<SourceKey, TargetKey>: NormalizeBaseAssociationOptions<BelongsToOptions<SourceKey, TargetKey>>

Type Parameters

  • SourceKey extends string

  • TargetKey extends string

NormalizedHasManyOptions<SourceKey, TargetKey>: NormalizeBaseAssociationOptions<HasManyOptions<SourceKey, TargetKey>>

Type Parameters

  • SourceKey extends string

  • TargetKey extends string

NormalizedHasOneOptions<SourceKey, TargetKey>: NormalizeBaseAssociationOptions<HasOneOptions<SourceKey, TargetKey>>

Type Parameters

  • SourceKey extends string

  • TargetKey extends string

NormalizedPoolOptions: Readonly<Required<PoolOptions>>
OperatorValues<AcceptableValues>: StaticValues<AcceptableValues> | DynamicValues<AcceptableValues>

Internal type - prone to changes. Do not export.

Type Parameters

  • AcceptableValues

Optional<T, K>: Omit<T, K> & Partial<Pick<T, K>>

Type helper for making certain fields of an object optional. This is helpful for creating the CreationAttributes from your Attributes for a Model.

Type Parameters

  • T

  • K extends keyof T

Order: Fn | Col | Literal | OrderItem[]
OrderItemAssociation: Association | ModelStatic<Model> | { as: string; model: ModelStatic<Model> } | string
OrderItemColumn: string | Col | Fn | Literal
PartlyRequired<T, K>: Omit<T, K> & Required<Pick<T, K>>

Type Parameters

  • T

  • K extends keyof T

ProjectionAlias: readonly [string | Literal | Fn | Col, string]

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').

Rangable<T>: readonly [lower: T | RangePart<T | number> | number | null, higher: T | RangePart<T | number> | number | null] | EmptyRange

Type Parameters

  • T

Range<T>: readonly [lower: RangePart<T | number>, higher: RangePart<T | number>] | EmptyRange

This type represents the output of the RANGE data type.

Type Parameters

  • T

RangePart<T>: { inclusive: boolean; value: T }

Type Parameters

  • T

Type declaration

  • inclusive: boolean
  • value: T
ReferentialAction: "CASCADE" | "RESTRICT" | "SET DEFAULT" | "SET NULL" | "NO ACTION"
SingleAssociationAccessors: { create: string; get: string; set: string }

Type declaration

  • create: string
  • get: string
  • set: string
StaticValues<Type>: Type extends Range<infer RangeType> ? [lower: RangeType | RangePart<RangeType>, higher: RangeType | RangePart<RangeType>] : Type extends any[] ? { readonly [ Key in keyof Type]: StaticValues<Type[Key]> } : Type extends null ? Type | WhereSerializableValue | null : Type | WhereSerializableValue

Represents acceptable Static values.

Static values, as opposed to DynamicValues. i.e. booleans, strings, etc...

Type Parameters

  • Type

TableName: string | TableNameWithSchema
TextLength: "tiny" | "medium" | "long"
UpdateValues<M>: { [ key in keyof Attributes<M>]?: Attributes<M>[key] | Fn | Col | Literal }

A pojo of values to update.

Used by Model.update

Type Parameters

WhereAttributeHash<TAttributes>: { [ AttributeName in keyof TAttributes as AttributeName extends string ? AttributeName | `$${AttributeName}$` : never]?: WhereAttributeHashValue<TAttributes[AttributeName]> } & { [ AttributeName in keyof TAttributes as AttributeName extends string ? `${AttributeName}.${string}` | `$${AttributeName}$.${string}` | `${AttributeName | `$${AttributeName}$` | `${AttributeName}.${string}` | `$${AttributeName}$.${string}`}::${string}` : never]?: WhereAttributeHashValue<any> } & {}

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 }

Type Parameters

  • TAttributes = any

WhereAttributeHashValue<AttributeType>: AllowNotOrAndRecursive<(AttributeType) extends any[] ? WhereOperators<AttributeType>[typeof Op.eq] | WhereOperators<AttributeType> : WhereOperators<AttributeType>[typeof Op.in] | WhereOperators<AttributeType>[typeof Op.eq] | WhereOperators<AttributeType>> | WhereAttributeHash<any>

Types that can be compared to an attribute in a WHERE context.

Type Parameters

  • AttributeType

WhereOptions<TAttributes>: AllowNotOrAndWithImplicitAndArrayRecursive<WhereAttributeHash<TAttributes> | Literal | Fn | Where | Json>

The type accepted by every where option

Type Parameters

  • TAttributes = any

WhereSerializableValue: boolean | string | number | Buffer | Date

Internal type - prone to changes. Do not export.

Variables

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

CreationAttributeBrand: unique symbol

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

ForeignKeyBrand: unique symbol

Dummy Symbol used as branding by {@link 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. Available in MySQL, Postgres and SQLite.

A pre-processed JSON data column. Only available in postgres.

A 24 bit integer.

A default value of the current timestamp

NonAttributeBrand: unique symbol

Dummy Symbol used as branding by NonAttribute.

Do not export, Do not use.

Op: OpTypes

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.

Functions

  • and<T>(...args: T): { [and]: T }
  • An AND query

    Type Parameters

    • T extends any[]

    Parameters

    • Rest ...args: T

      Each argument will be joined by AND

    Returns { [and]: T }

    • [and]: T
  • cast(val: unknown, type: string): Cast
  • Creates a object representing a call to the cast function.

    Parameters

    • val: unknown

      The value to cast

    • type: string

      The type to cast it to

    Returns Cast

  • col(columnName: string): Col
  • 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.

    Parameters

    • columnName: string

      The name of the column

    Returns Col

  • fn(sqlFunction: string, ...args: any): Fn
  • 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'))
    })

    Parameters

    • sqlFunction: string

      The function you want to call

    • Rest ...args: any

      All further arguments will be passed as arguments to the function

    Returns Fn

  • Returns true if the value is a model subclass.

    Type Parameters

    • M extends Model<any, any, M>

    Parameters

    • val: any

      The value whose type will be checked

    Returns val is ModelStatic<M>

  • 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.

    example

    isSameInitialModel(a, a.withScope('myScope')) // true;

    Parameters

    Returns boolean

  • Type Parameters

    • M extends Model<any, any, M>

    Parameters

    • val: any

    Returns val is ThroughOptions<M>

  • json(conditionsOrPath: string | object, value?: string | number | boolean): Json
  • Creates an object representing nested where conditions for postgres's json data-type.

    Parameters

    • conditionsOrPath: string | object

      A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax.

    • Optional value: string | number | boolean

      An optional value to compare against. Produces a string of the form "<json path> = '<value>'".

    Returns Json

  • Creates a object representing a literal, i.e. something that will not be escaped.

    Parameters

    • val: string

    Returns Literal

  • or<T>(...args: T): { [or]: T }
  • An OR query

    Type Parameters

    • T extends any[]

    Parameters

    • Rest ...args: T

      Each argument will be joined by OR

    Returns { [or]: T }

    • [or]: T
  • 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.

    example

    // Using an attribute as the left operand. // Equal to: WHERE first_name = 'Lily' where(User.rawAttributes.firstName, Op.eq, 'Lily');

    example

    // Using a column name as the left operand. // Equal to: WHERE first_name = 'Lily' where(col('first_name'), Op.eq, 'Lily');

    example

    // Using a SQL function on the left operand. // Equal to: WHERE LOWER(first_name) = 'lily' where(fn('LOWER', col('first_name')), Op.eq, 'lily');

    example

    // Using raw SQL as the left operand. // Equal to: WHERE 'Lily' = 'Lily' where(literal('Lily'), Op.eq, 'Lily');

    Type Parameters

    Parameters

    • leftOperand: WhereLeftOperand | Where<typeof eq>

      The left side of the comparison.

      • A value taken from YourModel.rawAttributes, to reference an attribute. The attribute must be defined in your model definition.
      • A Literal (using {@link Sequelize#literal})
      • A SQL Function (using {@link Sequelize#fn})
      • A Column name (using {@link Sequelize#col}) Note that simple strings to reference an attribute are not supported. You can use the POJO syntax instead.
    • operator: OpSymbol

      The comparison operator to use. If unspecified, defaults to {@link Op.eq}.

    • rightOperand: WhereOperators<any>[OpSymbol]

      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.

    Returns Where

  • Parameters

    • leftOperand: any
    • operator: string
    • rightOperand: any

    Returns Where

  • Parameters

    Returns Where

Generated using TypeDoc