Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SetupStep

Hierarchy

Index

Constructors

constructor

  • new SetupStep(values?: object, options?: BuildOptions): SetupStep
  • Parameters

    • Optional values: object
    • Optional options: BuildOptions

    Returns SetupStep

Properties

complete

complete: boolean

createdAt

createdAt: Date

Optional deletedAt

deletedAt: Date | any

guid

guid: string

Optional id

id: number | any

isNewRecord

isNewRecord: boolean

Returns true if this instance has not yet been persisted to the database

key

key: string

position

position: number

sequelize

sequelize: Sequelize

A reference to the sequelize instance

skipped

skipped: boolean

updatedAt

updatedAt: Date

Optional version

version: number | any

Static Readonly associations

associations: {}

An object hash from alias to association object

Type declaration

  • [key: string]: Association

Static isInitialized

isInitialized: boolean

Static Readonly options

options: InitOptions

The options that the model was initialized with

Static Readonly primaryKeyAttribute

primaryKeyAttribute: string

The name of the primary key attribute

Static Readonly primaryKeyAttributes

primaryKeyAttributes: string[]

The name of the primary key attributes

Static Readonly rawAttributes

rawAttributes: {}

The attributes of the model

Type declaration

  • [attribute: string]: ModelAttributeColumnOptions

Static Optional Readonly sequelize

sequelize: Sequelize

Reference to the sequelize instance the model was initialized with

Static Readonly tableName

tableName: string

The name of the database table

Methods

$add

  • $add<R>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: AssociationActionOptions): Promise<unknown>
  • Adds relation between specified instances and source instance

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: string
    • instances: R | R[] | string[] | string | number[] | number
    • Optional options: AssociationActionOptions

    Returns Promise<unknown>

$count

  • $count<R>(propertyKey: string, options?: AssociationCountOptions): Promise<number>
  • Counts related instances (specified by propertyKey) of source instance

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: string
    • Optional options: AssociationCountOptions

    Returns Promise<number>

$create

  • $create<R>(propertyKey: string, values: any, options?: AssociationCreateOptions): Promise<R>
  • Creates instances and relate them to source instance

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: string
    • values: any
    • Optional options: AssociationCreateOptions

    Returns Promise<R>

$get

  • $get<K>(propertyKey: K, options?: AssociationGetOptions): Promise<$GetType<this[K]>>
  • Returns related instance (specified by propertyKey) of source instance

    Type parameters

    • K: keyof this

    Parameters

    • propertyKey: K
    • Optional options: AssociationGetOptions

    Returns Promise<$GetType<this[K]>>

$has

  • $has<R>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: AssociationGetOptions): Promise<boolean>
  • Checks if specified instances is related to source instance

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: string
    • instances: R | R[] | string[] | string | number[] | number
    • Optional options: AssociationGetOptions

    Returns Promise<boolean>

$remove

  • $remove<R>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: any): Promise<any>
  • Removes specified instances from source instance

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: string
    • instances: R | R[] | string[] | string | number[] | number
    • Optional options: any

    Returns Promise<any>

$set

  • $set<R>(propertyKey: keyof this, instances: R | R[] | string[] | string | number[] | number, options?: AssociationActionOptions): Promise<unknown>
  • Sets relation between specified instances and source instance (replaces old relations)

    Type parameters

    • R: Model<R>

    Parameters

    • propertyKey: keyof this
    • instances: R | R[] | string[] | string | number[] | number
    • Optional options: AssociationActionOptions

    Returns Promise<unknown>

addHook

  • addHook<K>(hookType: K, name: string, fn: SequelizeHooks[K]): this
  • addHook<K>(hookType: K, fn: SequelizeHooks[K]): this
  • Add a hook to the model

    Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • name: string

      Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.

    • fn: SequelizeHooks[K]

    Returns this

  • Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • fn: SequelizeHooks[K]

    Returns this

apiData

  • apiData(): Promise<{ complete: boolean; createdAt: number; cta: string; description: string; guid: string; href: string; key: string; outcome: string; position: number; skipped: boolean; title: string; updatedAt: number }>
  • Returns Promise<{ complete: boolean; createdAt: number; cta: string; description: string; guid: string; href: string; key: string; outcome: string; position: number; skipped: boolean; title: string; updatedAt: number }>

changed

  • changed<K>(key: K): boolean
  • changed<K>(key: K, dirty: boolean): void
  • changed(): false | string[]
  • If changed is called with a string it will return a boolean indicating whether the value of that key in dataValues is different from the value in _previousDataValues.

    If changed is called without an argument, it will return an array of keys that have changed.

    If changed is called with two arguments, it will set the property to dirty.

    If changed is called without an argument and no keys have changed, it will return false.

    Type parameters

    • K: keyof this

    Parameters

    • key: K

    Returns boolean

  • Type parameters

    • K: keyof this

    Parameters

    • key: K
    • dirty: boolean

    Returns void

  • Returns false | string[]

decrement

  • decrement<K>(fields: K | K[] | Partial<this>, options?: IncrementDecrementOptionsWithBy): Promise<this>
  • Decrement the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The decrement is done using a

    SET column = column - X

    query. To get the correct value after an decrement into the Instance you should do a reload.

    instance.decrement('number') // decrement number by 1
    instance.decrement(['number', 'count'], { by: 2 }) // decrement number and count by 2
    instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42, and tries by 1.
                                                           // `by` is ignored, since each column has its own
                                                           // value

    Type parameters

    • K: keyof this

    Parameters

    • fields: K | K[] | Partial<this>

      If a string is provided, that column is decremented by the value of by given in options. If an array is provided, the same is true for each column. If and object is provided, each column is decremented by the value given

    • Optional options: IncrementDecrementOptionsWithBy

    Returns Promise<this>

destroy

  • destroy(options?: InstanceDestroyOptions): Promise<void>
  • Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will either be completely deleted, or have its deletedAt timestamp set to the current time.

    Parameters

    • Optional options: InstanceDestroyOptions

    Returns Promise<void>

equals

  • equals(other: this): boolean
  • Check whether all values of this and other Instance are the same

    Parameters

    • other: this

    Returns boolean

equalsOneOf

  • equalsOneOf(others: this[]): boolean
  • Check if this is eqaul to one of others by calling equals

    Parameters

    • others: this[]

    Returns boolean

filteredDataForLogging

  • filteredDataForLogging(): Promise<{}>

get

  • get(options?: { clone?: boolean; plain?: boolean }): object
  • get<K>(key: K, options?: { clone?: boolean; plain?: boolean }): this[K]
  • get(key: string, options?: { clone?: boolean; plain?: boolean }): unknown
  • If no key is given, returns all values of the instance, also invoking virtual getters.

    If key is given and a field or virtual getter is present for the key it will call that getter - else it will return the value for key.

    Parameters

    • Optional options: { clone?: boolean; plain?: boolean }
      • Optional clone?: boolean
      • Optional plain?: boolean

        If set to true, included instances will be returned as plain objects

    Returns object

  • Type parameters

    • K: keyof this

    Parameters

    • key: K
    • Optional options: { clone?: boolean; plain?: boolean }
      • Optional clone?: boolean
      • Optional plain?: boolean

    Returns this[K]

  • Parameters

    • key: string
    • Optional options: { clone?: boolean; plain?: boolean }
      • Optional clone?: boolean
      • Optional plain?: boolean

    Returns unknown

getCta

  • Parameters

    Returns string

getDataValue

  • getDataValue<K>(key: K): this[K]
  • Get the value of the underlying data value

    Type parameters

    • K: keyof this

    Parameters

    • key: K

    Returns this[K]

getDescription

  • Parameters

    Returns string

getHref

  • Parameters

    Returns string

getOutcome

  • Parameters

    Returns Promise<string>

getSetupStepDescription

getTitle

  • Parameters

    Returns string

guidPrefix

  • guidPrefix(): string

hasHook

  • hasHook<K>(hookType: K): boolean
  • Check whether the mode has any hooks of this type

    Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K

    Returns boolean

hasHooks

  • hasHooks<K>(hookType: K): boolean
  • Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K

    Returns boolean

increment

  • increment<K>(fields: K | K[] | Partial<this>, options?: IncrementDecrementOptionsWithBy): Promise<this>
  • Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the Instance. The increment is done using a

    SET column = column + X

    query. To get the correct value after an increment into the Instance you should do a reload.

    instance.increment('number') // increment number by 1
    instance.increment(['number', 'count'], { by: 2 }) // increment number and count by 2
    instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42, and tries by 1.
                                                           // `by` is ignored, since each column has its own
                                                           // value

    Type parameters

    • K: keyof this

    Parameters

    • fields: K | K[] | Partial<this>

      If a string is provided, that column is incremented by the value of by given in options. If an array is provided, the same is true for each column. If and object is provided, each column is incremented by the value given.

    • Optional options: IncrementDecrementOptionsWithBy

    Returns Promise<this>

logMessage

  • logMessage(verb: "create" | "update" | "destroy"): Promise<string>
  • Parameters

    • verb: "create" | "update" | "destroy"

    Returns Promise<string>

performCheck

  • Parameters

    Returns Promise<boolean>

previous

  • previous<K>(key: K): this[K]
  • Returns the previous value for key from _previousDataValues.

    Type parameters

    • K: keyof this

    Parameters

    • key: K

    Returns this[K]

reload

  • reload(options?: FindOptions): Promise<this>
  • Parameters

    • Optional options: FindOptions

    Returns Promise<this>

removeHook

  • removeHook<K>(hookType: K, name: string): this
  • Remove hook from the model

    Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • name: string

    Returns this

restore

  • restore(options?: InstanceRestoreOptions): Promise<void>
  • Restore the row corresponding to this instance. Only available for paranoid models.

    Parameters

    • Optional options: InstanceRestoreOptions

    Returns Promise<void>

save

  • save(options?: SaveOptions): Promise<this>
  • Validate this instance, and if the validation passes, persist it to the database.

    On success, the callback will be called with this instance. On validation error, the callback will be called with an instance of Sequelize.ValidationError. This error will have a property for each of the fields for which validation failed, with the error message for that field.

    Parameters

    • Optional options: SaveOptions

    Returns Promise<this>

set

  • set<K>(key: K, value: this[K], options?: SetOptions): this
  • set(keys: Partial<this>, options?: SetOptions): this
  • Set is used to update values on the instance (the sequelize representation of the instance that is, remember that nothing will be persisted before you actually call save). In its most basic form set will update a value stored in the underlying dataValues object. However, if a custom setter function is defined for the key, that function will be called instead. To bypass the setter, you can pass raw: true in the options object.

    If set is called with an object, it will loop over the object, and call set recursively for each key, value pair. If you set raw to true, the underlying dataValues will either be set directly to the object passed, or used to extend dataValues, if dataValues already contain values.

    When set is called, the previous value of the field is stored and sets a changed flag(see changed).

    Set can also be used to build instances for associations, if you have values for those. When using set with associations you need to make sure the property key matches the alias of the association while also making sure that the proper include options have been set (from .build() or .findOne())

    If called with a dot.seperated key on a JSON/JSONB attribute it will set the value nested and flag the entire object as changed.

    Type parameters

    • K: keyof this

    Parameters

    • key: K
    • value: this[K]
    • Optional options: SetOptions

    Returns this

  • Parameters

    • keys: Partial<this>
    • Optional options: SetOptions

    Returns this

setAttributes

  • setAttributes<K>(key: K, value: this[K], options?: SetOptions): this
  • setAttributes(keys: object, options?: SetOptions): this
  • Type parameters

    • K: keyof this

    Parameters

    • key: K
    • value: this[K]
    • Optional options: SetOptions

    Returns this

  • Parameters

    • keys: object
    • Optional options: SetOptions

    Returns this

setDataValue

  • setDataValue<K>(key: K, value: this[K]): void
  • Update the underlying data value

    Type parameters

    • K: keyof this

    Parameters

    • key: K
    • value: this[K]

    Returns void

toJSON

  • toJSON(): object
  • Convert the instance to a JSON representation. Proxies to calling get with no keys. This means get all values gotten from the DB, and apply all custom getters.

    Returns object

update

  • update<K>(key: K, value: this[K], options?: InstanceUpdateOptions): Promise<this>
  • update(keys: object, options?: InstanceUpdateOptions): Promise<this>
  • This is the same as calling set and then calling save.

    Type parameters

    • K: keyof this

    Parameters

    • key: K
    • value: this[K]
    • Optional options: InstanceUpdateOptions

    Returns Promise<this>

  • Parameters

    • keys: object
    • Optional options: InstanceUpdateOptions

    Returns Promise<this>

validate

  • validate(options?: ValidationOptions): Promise<void>
  • Validate the attribute of this instance according to validation rules set in the model definition.

    Emits null if and only if validation successful; otherwise an Error instance containing { field name : [error msgs] } entries.

    Parameters

    • Optional options: ValidationOptions

    Returns Promise<void>

where

  • where(): object
  • Get an object representing the query for this instance, use with options.where

    Returns object

Static addHook

  • addHook<C, K>(hookType: K, name: string, fn: SequelizeHooks[K]): C
  • addHook<C, K>(hookType: K, fn: SequelizeHooks[K]): C
  • Add a hook to the model

    Type parameters

    • C: typeof Hooks

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • name: string

      Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.

    • fn: SequelizeHooks[K]

    Returns C

  • Type parameters

    • C: typeof Hooks

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • fn: SequelizeHooks[K]

    Returns C

Static addScope

  • addScope(name: string, scope: FindOptions, options?: AddScopeOptions): void
  • addScope(name: string, scope: (...args: any[]) => FindOptions, options?: AddScopeOptions): void
  • Add a new scope to the model

    This is especially useful for adding scopes with includes, when the model you want to include is not available at the time this model is defined. By default this will throw an error if a scope with that name already exists. Pass override: true in the options object to silence this error.

    Parameters

    • name: string
    • scope: FindOptions
    • Optional options: AddScopeOptions

    Returns void

  • Parameters

    • name: string
    • scope: (...args: any[]) => FindOptions
        • (...args: any[]): FindOptions
        • Parameters

          • Rest ...args: any[]

          Returns FindOptions

    • Optional options: AddScopeOptions

    Returns void

Static afterBulkCreate

  • afterBulkCreate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instances: M[], options: BulkCreateOptions) => HookReturn): void
  • afterBulkCreate<M>(this: { constructor: any } & typeof Model, fn: (instances: M[], options: BulkCreateOptions) => HookReturn): void
  • A hook that is run after creating instances in bulk

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instances: M[], options: BulkCreateOptions) => HookReturn

      A callback function that is called with instances, options

        • (instances: M[], options: BulkCreateOptions): HookReturn
        • Parameters

          • instances: M[]
          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instances: M[], options: BulkCreateOptions) => HookReturn
        • (instances: M[], options: BulkCreateOptions): HookReturn
        • Parameters

          • instances: M[]
          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

Static afterBulkDestroy

  • afterBulkDestroy(name: string, fn: (options: DestroyOptions) => HookReturn): void
  • afterBulkDestroy(fn: (options: DestroyOptions) => HookReturn): void
  • A hook that is run after destroying instances in bulk

    Parameters

    • name: string
    • fn: (options: DestroyOptions) => HookReturn

      A callback function that is called with options

        • (options: DestroyOptions): HookReturn
        • Parameters

          • options: DestroyOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: DestroyOptions) => HookReturn
        • (options: DestroyOptions): HookReturn
        • Parameters

          • options: DestroyOptions

          Returns HookReturn

    Returns void

Static afterBulkSync

  • afterBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void
  • afterBulkSync(fn: (options: SyncOptions) => HookReturn): void
  • A hook that is run after sequelize.sync call

    Parameters

    • name: string
    • fn: (options: SyncOptions) => HookReturn

      A callback function that is called with options passed to sequelize.sync

        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: SyncOptions) => HookReturn
        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

Static afterBulkUpdate

  • afterBulkUpdate(name: string, fn: (options: UpdateOptions) => HookReturn): void
  • afterBulkUpdate(fn: (options: UpdateOptions) => HookReturn): void
  • A hook that is run after updating instances in bulk

    Parameters

    • name: string
    • fn: (options: UpdateOptions) => HookReturn

      A callback function that is called with options

        • (options: UpdateOptions): HookReturn
        • Parameters

          • options: UpdateOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: UpdateOptions) => HookReturn
        • (options: UpdateOptions): HookReturn
        • Parameters

          • options: UpdateOptions

          Returns HookReturn

    Returns void

Static afterCreate

  • afterCreate<M>(this: { constructor: any } & typeof Model, name: string, fn: (attributes: M, options: CreateOptions) => HookReturn): void
  • afterCreate<M>(this: { constructor: any } & typeof Model, fn: (attributes: M, options: CreateOptions) => HookReturn): void
  • A hook that is run after creating a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (attributes: M, options: CreateOptions) => HookReturn

      A callback function that is called with attributes, options

        • (attributes: M, options: CreateOptions): HookReturn
        • Parameters

          • attributes: M
          • options: CreateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (attributes: M, options: CreateOptions) => HookReturn
        • (attributes: M, options: CreateOptions): HookReturn
        • Parameters

          • attributes: M
          • options: CreateOptions

          Returns HookReturn

    Returns void

Static afterDestroy

  • afterDestroy<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: InstanceDestroyOptions) => HookReturn): void
  • afterDestroy<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: InstanceDestroyOptions) => HookReturn): void
  • A hook that is run after destroying a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: InstanceDestroyOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: InstanceDestroyOptions): HookReturn
        • Parameters

          • instance: M
          • options: InstanceDestroyOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: InstanceDestroyOptions) => HookReturn
        • (instance: M, options: InstanceDestroyOptions): HookReturn
        • Parameters

          • instance: M
          • options: InstanceDestroyOptions

          Returns HookReturn

    Returns void

Static afterFind

  • afterFind<M>(this: { constructor: any } & typeof Model, name: string, fn: (instancesOrInstance: M[] | M | null, options: FindOptions) => HookReturn): void
  • afterFind<M>(this: { constructor: any } & typeof Model, fn: (instancesOrInstance: M[] | M | null, options: FindOptions) => HookReturn): void
  • A hook that is run after a find (select) query

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instancesOrInstance: M[] | M | null, options: FindOptions) => HookReturn

      A callback function that is called with instance(s), options

        • (instancesOrInstance: M[] | M | null, options: FindOptions): HookReturn
        • Parameters

          • instancesOrInstance: M[] | M | null
          • options: FindOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instancesOrInstance: M[] | M | null, options: FindOptions) => HookReturn
        • (instancesOrInstance: M[] | M | null, options: FindOptions): HookReturn
        • Parameters

          • instancesOrInstance: M[] | M | null
          • options: FindOptions

          Returns HookReturn

    Returns void

Static afterSave

  • afterSave<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn): void
  • afterSave<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn): void
  • A hook that is run after creating or updating a single instance, It proxies afterCreate and afterUpdate

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: UpdateOptions | SaveOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions | SaveOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn
        • (instance: M, options: UpdateOptions | SaveOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions | SaveOptions

          Returns HookReturn

    Returns void

Static afterSync

  • afterSync(name: string, fn: (options: SyncOptions) => HookReturn): void
  • afterSync(fn: (options: SyncOptions) => HookReturn): void
  • A hook that is run after Model.sync call

    Parameters

    • name: string
    • fn: (options: SyncOptions) => HookReturn

      A callback function that is called with options passed to Model.sync

        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: SyncOptions) => HookReturn
        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

Static afterUpdate

  • afterUpdate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: UpdateOptions) => HookReturn): void
  • afterUpdate<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: UpdateOptions) => HookReturn): void
  • A hook that is run after updating a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: UpdateOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: UpdateOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: UpdateOptions) => HookReturn
        • (instance: M, options: UpdateOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions

          Returns HookReturn

    Returns void

Static afterValidate

  • afterValidate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: ValidationOptions) => HookReturn): void
  • afterValidate<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: ValidationOptions) => HookReturn): void
  • A hook that is run after validation

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: ValidationOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: ValidationOptions): HookReturn
        • Parameters

          • instance: M
          • options: ValidationOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: ValidationOptions) => HookReturn
        • (instance: M, options: ValidationOptions): HookReturn
        • Parameters

          • instance: M
          • options: ValidationOptions

          Returns HookReturn

    Returns void

Static aggregate

  • aggregate<M, T>(this: { constructor: any } & typeof Model, field: keyof M, aggregateFunction: string, options?: AggregateOptions<T>): Promise<T>
  • Run an aggregation method on the specified field

    Type parameters

    • M: Model

    • T: DataType | unknown

    Parameters

    • this: { constructor: any } & typeof Model
    • field: keyof M

      The field to aggregate over. Can be a field name or *

    • aggregateFunction: string

      The function to use for aggregation, e.g. sum, max etc.

    • Optional options: AggregateOptions<T>

      Query options. See sequelize.query for full options

    Returns Promise<T>

    Returns the aggregate result cast to options.dataType, unless options.plain is false, in which case the complete data result is returned.

Static beforeBulkCreate

  • beforeBulkCreate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instances: M[], options: BulkCreateOptions) => HookReturn): void
  • beforeBulkCreate<M>(this: { constructor: any } & typeof Model, fn: (instances: M[], options: BulkCreateOptions) => HookReturn): void
  • A hook that is run before creating instances in bulk

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instances: M[], options: BulkCreateOptions) => HookReturn

      A callback function that is called with instances, options

        • (instances: M[], options: BulkCreateOptions): HookReturn
        • Parameters

          • instances: M[]
          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instances: M[], options: BulkCreateOptions) => HookReturn
        • (instances: M[], options: BulkCreateOptions): HookReturn
        • Parameters

          • instances: M[]
          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

Static beforeBulkDestroy

  • beforeBulkDestroy(name: string, fn: (options: BulkCreateOptions) => HookReturn): void
  • beforeBulkDestroy(fn: (options: BulkCreateOptions) => HookReturn): void
  • A hook that is run before destroying instances in bulk

    Parameters

    • name: string
    • fn: (options: BulkCreateOptions) => HookReturn

      A callback function that is called with options

        • (options: BulkCreateOptions): HookReturn
        • Parameters

          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: BulkCreateOptions) => HookReturn
        • (options: BulkCreateOptions): HookReturn
        • Parameters

          • options: BulkCreateOptions

          Returns HookReturn

    Returns void

Static beforeBulkSync

  • beforeBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void
  • beforeBulkSync(fn: (options: SyncOptions) => HookReturn): void
  • A hook that is run before sequelize.sync call

    Parameters

    • name: string
    • fn: (options: SyncOptions) => HookReturn

      A callback function that is called with options passed to sequelize.sync

        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: SyncOptions) => HookReturn
        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

Static beforeBulkUpdate

  • beforeBulkUpdate(name: string, fn: (options: UpdateOptions) => HookReturn): void
  • beforeBulkUpdate(fn: (options: UpdateOptions) => HookReturn): void
  • A hook that is run after updating instances in bulk

    Parameters

    • name: string
    • fn: (options: UpdateOptions) => HookReturn

      A callback function that is called with options

        • (options: UpdateOptions): HookReturn
        • Parameters

          • options: UpdateOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: UpdateOptions) => HookReturn
        • (options: UpdateOptions): HookReturn
        • Parameters

          • options: UpdateOptions

          Returns HookReturn

    Returns void

Static beforeCount

  • beforeCount(name: string, fn: (options: CountOptions) => HookReturn): void
  • beforeCount(fn: (options: CountOptions) => HookReturn): void
  • A hook that is run before a count query

    Parameters

    • name: string
    • fn: (options: CountOptions) => HookReturn

      A callback function that is called with options

        • (options: CountOptions): HookReturn
        • Parameters

          • options: CountOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: CountOptions) => HookReturn
        • (options: CountOptions): HookReturn
        • Parameters

          • options: CountOptions

          Returns HookReturn

    Returns void

Static beforeCreate

  • beforeCreate<M>(this: { constructor: any } & typeof Model, name: string, fn: (attributes: M, options: CreateOptions) => HookReturn): void
  • beforeCreate<M>(this: { constructor: any } & typeof Model, fn: (attributes: M, options: CreateOptions) => HookReturn): void
  • A hook that is run before creating a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (attributes: M, options: CreateOptions) => HookReturn

      A callback function that is called with attributes, options

        • (attributes: M, options: CreateOptions): HookReturn
        • Parameters

          • attributes: M
          • options: CreateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (attributes: M, options: CreateOptions) => HookReturn
        • (attributes: M, options: CreateOptions): HookReturn
        • Parameters

          • attributes: M
          • options: CreateOptions

          Returns HookReturn

    Returns void

Static beforeDestroy

  • beforeDestroy<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: InstanceDestroyOptions) => HookReturn): void
  • beforeDestroy<M>(this: { constructor: any } & typeof Model, fn: (instance: Model, options: InstanceDestroyOptions) => HookReturn): void
  • A hook that is run before destroying a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: InstanceDestroyOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: InstanceDestroyOptions): HookReturn
        • Parameters

          • instance: M
          • options: InstanceDestroyOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: Model, options: InstanceDestroyOptions) => HookReturn
        • (instance: Model, options: InstanceDestroyOptions): HookReturn
        • Parameters

          • instance: Model
          • options: InstanceDestroyOptions

          Returns HookReturn

    Returns void

Static beforeFind

  • beforeFind(name: string, fn: (options: FindOptions) => HookReturn): void
  • beforeFind(fn: (options: FindOptions) => HookReturn): void
  • A hook that is run before a find (select) query

    Parameters

    • name: string
    • fn: (options: FindOptions) => HookReturn

      A callback function that is called with options

        • (options: FindOptions): HookReturn
        • Parameters

          • options: FindOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: FindOptions) => HookReturn
        • (options: FindOptions): HookReturn
        • Parameters

          • options: FindOptions

          Returns HookReturn

    Returns void

Static beforeFindAfterExpandIncludeAll

  • beforeFindAfterExpandIncludeAll(name: string, fn: (options: FindOptions) => HookReturn): void
  • beforeFindAfterExpandIncludeAll(fn: (options: FindOptions) => HookReturn): void
  • A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded

    Parameters

    • name: string
    • fn: (options: FindOptions) => HookReturn

      A callback function that is called with options

        • (options: FindOptions): HookReturn
        • Parameters

          • options: FindOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: FindOptions) => HookReturn
        • (options: FindOptions): HookReturn
        • Parameters

          • options: FindOptions

          Returns HookReturn

    Returns void

Static beforeFindAfterOptions

  • beforeFindAfterOptions(name: string, fn: (options: FindOptions) => HookReturn): void
  • beforeFindAfterOptions(fn: (options: FindOptions) => void): HookReturn
  • A hook that is run before a find (select) query, after all option parsing is complete

    Parameters

    • name: string
    • fn: (options: FindOptions) => HookReturn

      A callback function that is called with options

        • (options: FindOptions): HookReturn
        • Parameters

          • options: FindOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: FindOptions) => void
        • (options: FindOptions): void
        • Parameters

          • options: FindOptions

          Returns void

    Returns HookReturn

Static beforeSave

  • beforeSave<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn): void
  • beforeSave<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn): void
  • A hook that is run before creating or updating a single instance, It proxies beforeCreate and beforeUpdate

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: UpdateOptions | SaveOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions | SaveOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: UpdateOptions | SaveOptions) => HookReturn
        • (instance: M, options: UpdateOptions | SaveOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions | SaveOptions

          Returns HookReturn

    Returns void

Static beforeSync

  • beforeSync(name: string, fn: (options: SyncOptions) => HookReturn): void
  • beforeSync(fn: (options: SyncOptions) => HookReturn): void
  • A hook that is run before Model.sync call

    Parameters

    • name: string
    • fn: (options: SyncOptions) => HookReturn

      A callback function that is called with options passed to Model.sync

        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

  • Parameters

    • fn: (options: SyncOptions) => HookReturn
        • (options: SyncOptions): HookReturn
        • Parameters

          • options: SyncOptions

          Returns HookReturn

    Returns void

Static beforeUpdate

  • beforeUpdate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: UpdateOptions) => HookReturn): void
  • beforeUpdate<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: UpdateOptions) => HookReturn): void
  • A hook that is run before updating a single instance

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: UpdateOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: UpdateOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: UpdateOptions) => HookReturn
        • (instance: M, options: UpdateOptions): HookReturn
        • Parameters

          • instance: M
          • options: UpdateOptions

          Returns HookReturn

    Returns void

Static beforeValidate

  • beforeValidate<M>(this: { constructor: any } & typeof Model, name: string, fn: (instance: M, options: ValidationOptions) => HookReturn): void
  • beforeValidate<M>(this: { constructor: any } & typeof Model, fn: (instance: M, options: ValidationOptions) => HookReturn): void
  • A hook that is run before validation

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • name: string
    • fn: (instance: M, options: ValidationOptions) => HookReturn

      A callback function that is called with instance, options

        • (instance: M, options: ValidationOptions): HookReturn
        • Parameters

          • instance: M
          • options: ValidationOptions

          Returns HookReturn

    Returns void

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • fn: (instance: M, options: ValidationOptions) => HookReturn
        • (instance: M, options: ValidationOptions): HookReturn
        • Parameters

          • instance: M
          • options: ValidationOptions

          Returns HookReturn

    Returns void

Static belongsTo

  • belongsTo<M, T>(this: ModelCtor<M>, target: ModelCtor<T>, options?: BelongsToOptions): BelongsTo<M, T>
  • Creates an association between this (the source) and the provided target. The foreign key is added on the source.

    Example: Profile.belongsTo(User). This will add userId to the profile table.

    Type parameters

    • M: Model

    • T: Model

    Parameters

    • this: ModelCtor<M>
    • target: ModelCtor<T>

      The model that will be associated with hasOne relationship

    • Optional options: BelongsToOptions

      Options for the association

    Returns BelongsTo<M, T>

Static belongsToMany

  • belongsToMany<M, T>(this: ModelCtor<M>, target: ModelCtor<T>, options: BelongsToManyOptions): BelongsToMany<M, T>
  • Create an N:M association with a join table

    User.belongsToMany(Project)
    Project.belongsToMany(User)

    By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as through in the options.

    If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before with a join table that stores whether the project has been started yet:

    class UserProjects extends Model {}
    UserProjects.init({
      started: Sequelize.BOOLEAN
    }, { sequelize });
    User.belongsToMany(Project, { through: UserProjects })
    Project.belongsToMany(User, { through: UserProjects })
    jan.addProject(homework, { started: false }) // The homework project is not started yet
    jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner has been started

    If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:

    p1.userprojects {
      started: true
    }
    user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that.

    Similarily, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.

    user.getProjects().then(projects => {
      const p1 = projects[0]
      p1.userprojects.started // Is this project started yet?
    })

    Type parameters

    • M: Model

    • T: Model

    Parameters

    • this: ModelCtor<M>
    • target: ModelCtor<T>

      The model that will be associated with hasOne relationship

    • options: BelongsToManyOptions

      Options for the association

    Returns BelongsToMany<M, T>

Static broadcast

  • broadcast(instance: any): Promise<void>
  • Parameters

    • instance: any

    Returns Promise<void>

Static build

  • build<M>(this: { constructor: any } & typeof Model, record?: object, options?: BuildOptions): M
  • Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional record: object
    • Optional options: BuildOptions

    Returns M

Static bulkBuild

  • bulkBuild<M>(this: { constructor: any } & typeof Model, records: object[], options?: BuildOptions): M[]
  • Undocumented bulkBuild

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • records: object[]
    • Optional options: BuildOptions

    Returns M[]

Static bulkCreate

  • bulkCreate<M>(this: { constructor: any } & typeof Model, records: object[], options?: BulkCreateOptions): Promise<M[]>
  • Create and insert multiple instances in bulk.

    The success handler is passed an array of instances, but please notice that these may not completely represent the state of the rows in the DB. This is because MySQL and SQLite do not make it easy to obtain back automatically generated IDs and other default values in a way that can be mapped to multiple records. To obtain Instances for the newly created values, you will need to query for them again.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • records: object[]

      List of objects (key/value pairs) to create instances from

    • Optional options: BulkCreateOptions

    Returns Promise<M[]>

Static count

  • count(options: CountWithOptions): Promise<{}>
  • count(options?: CountOptions): Promise<number>
  • Count number of records if group by is used

    Parameters

    • options: CountWithOptions

    Returns Promise<{}>

  • Count the number of records matching the provided where clause.

    If you provide an include option, the number of matching associations will be counted instead.

    Parameters

    • Optional options: CountOptions

    Returns Promise<number>

Static create

  • create<M>(this: { constructor: any } & typeof Model, values?: object, options?: CreateOptions): Promise<M>
  • create(values: object, options: CreateOptions & { returning: false }): Promise<void>
  • Builds a new model instance and calls save on it.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional values: object
    • Optional options: CreateOptions

    Returns Promise<M>

  • Parameters

    • values: object
    • options: CreateOptions & { returning: false }

    Returns Promise<void>

Static describe

  • describe(): Promise<object>
  • Run a describe query on the table. The result will be return to the listener as a hash of attributes and their types.

    Returns Promise<object>

Static destroy

  • destroy(options?: DestroyOptions): Promise<number>
  • Delete multiple instances, or set their deletedAt timestamp to the current time if paranoid is enabled.

    Parameters

    • Optional options: DestroyOptions

    Returns Promise<number>

    Promise The number of destroyed rows

Static drop

  • drop(options?: DropOptions): Promise<void>
  • Drop the table represented by this Model

    Parameters

    • Optional options: DropOptions

    Returns Promise<void>

Static findAll

  • findAll<M>(this: { constructor: any } & typeof Model, options?: FindOptions): Promise<M[]>
  • Search for multiple instances.

    Simple search using AND and =

    Model.findAll({
      where: {
        attr1: 42,
        attr2: 'cake'
      }
    })
    WHERE attr1 = 42 AND attr2 = 'cake'

    Using greater than, less than etc.

    
    Model.findAll({
      where: {
        attr1: {
          gt: 50
        },
        attr2: {
          lte: 45
        },
        attr3: {
          in: [1,2,3]
        },
        attr4: {
          ne: 5
        }
      }
    })
    WHERE attr1 > 50 AND attr2 <= 45 AND attr3 IN (1,2,3) AND attr4 != 5

    Possible options are: [Op.ne], [Op.in], [Op.not], [Op.notIn], [Op.gte], [Op.gt], [Op.lte], [Op.lt], [Op.like], [Op.ilike]/[Op.iLike], [Op.notLike], [Op.notILike], '..'/[Op.between], '!..'/[Op.notBetween], '&&'/[Op.overlap], '@>'/[Op.contains], '<@'/[Op.contained]

    Queries using OR

    Model.findAll({
      where: Sequelize.and(
        { name: 'a project' },
        Sequelize.or(
          { id: [1,2,3] },
          { id: { gt: 10 } }
        )
      )
    })
    WHERE name = 'a project' AND (id` IN (1,2,3) OR id > 10)

    The success listener is called with an array of instances if the query succeeds.

    see

    {Sequelize#query}

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional options: FindOptions

    Returns Promise<M[]>

Static findAndCountAll

  • findAndCountAll<M>(this: { constructor: any } & typeof Model, options?: FindAndCountOptions): Promise<{ count: number; rows: M[] }>
  • Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging

    Model.findAndCountAll({
      where: ...,
      limit: 12,
      offset: 12
    }).then(result => {
      ...
    })

    In the above example, result.rows will contain rows 13 through 24, while result.count will return the total number of rows that matched your query.

    When you add includes, only those which are required (either because they have a where clause, or because required is explicitly set to true on the include) will be added to the count part.

    Suppose you want to find all users who have a profile attached:

    User.findAndCountAll({
      include: [
         { model: Profile, required: true}
      ],
      limit 3
    });

    Because the include for Profile has required set it will result in an inner join, and only the users who have a profile will be counted. If we remove required from the include, both users with and without profiles will be counted

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional options: FindAndCountOptions

    Returns Promise<{ count: number; rows: M[] }>

Static findByGuid

  • findByGuid(guid: string): Promise<SetupStep>

Static findByPk

  • findByPk<M>(this: { constructor: any } & typeof Model, identifier?: Identifier, options?: Omit<FindOptions, "where">): Promise<M | null>
  • findByPk<M>(this: { constructor: any } & typeof Model, identifier: Identifier, options: Omit<NonNullFindOptions, "where">): Promise<M>
  • Search for a single instance by its primary key. This applies LIMIT 1, so the listener will always be called with a single instance.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional identifier: Identifier
    • Optional options: Omit<FindOptions, "where">

    Returns Promise<M | null>

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • identifier: Identifier
    • options: Omit<NonNullFindOptions, "where">

    Returns Promise<M>

Static findCreateFind

  • findCreateFind<M>(this: { constructor: any } & typeof Model, options: FindOrCreateOptions): Promise<[M, boolean]>
  • A more performant findOrCreate that will not work under a transaction (at least not in postgres) Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • options: FindOrCreateOptions

    Returns Promise<[M, boolean]>

Static findOne

  • findOne<M>(this: { constructor: any } & typeof Model, options?: FindOptions): Promise<M | null>
  • findOne<M>(this: { constructor: any } & typeof Model, options: NonNullFindOptions): Promise<M>
  • Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • Optional options: FindOptions

    Returns Promise<M | null>

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • options: NonNullFindOptions

    Returns Promise<M>

Static findOrBuild

  • findOrBuild<M>(this: { constructor: any } & typeof Model, options: FindOrCreateOptions): Promise<[M, boolean]>
  • Find a row that matches the query, or build (but don't save) the row if none is found. The successfull result of the promise will be (instance, initialized) - Make sure to use .then(([...]))

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • options: FindOrCreateOptions

    Returns Promise<[M, boolean]>

Static findOrCreate

  • findOrCreate<M>(this: { constructor: any } & typeof Model, options: FindOrCreateOptions): Promise<[M, boolean]>
  • Find a row that matches the query, or build and save the row if none is found The successful result of the promise will be (instance, created) - Make sure to use .then(([...]))

    If no transaction is passed in the options object, a new transaction will be created internally, to prevent the race condition where a matching row is created by another connection after the find but before the insert call. However, it is not always possible to handle this case in SQLite, specifically if one transaction inserts and another tries to select before the first one has comitted. In this case, an instance of sequelize.TimeoutError will be thrown instead. If a transaction is created, a savepoint will be created instead, and any unique constraint violation will be handled internally.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • options: FindOrCreateOptions

    Returns Promise<[M, boolean]>

Static generateGuid

  • generateGuid(instance: any): void
  • Parameters

    • instance: any

    Returns void

Static getTableName

  • getTableName(): string | { delimiter: string; schema: string; tableName: string }
  • Get the tablename of the model, taking schema into account. The method will return The name as a string if the model has no schema, or an object with tableName, schema and delimiter properties.

    Returns string | { delimiter: string; schema: string; tableName: string }

Static hasHook

  • hasHook<K>(hookType: K): boolean
  • Check whether the mode has any hooks of this type

    Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K

    Returns boolean

Static hasHooks

  • hasHooks<K>(hookType: K): boolean
  • Type parameters

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K

    Returns boolean

Static hasMany

  • hasMany<M, T>(this: ModelCtor<M>, target: ModelCtor<T>, options?: HasManyOptions): HasMany<M, T>
  • Create an association that is either 1:m or n:m.

    // Create a 1:m association between user and project
    User.hasMany(Project)
    // Create a n:m association between user and project
    User.hasMany(Project)
    Project.hasMany(User)

    By default, the name of the join table will be source+target, so in this case projectsusers. This can be overridden by providing either a string or a Model as through in the options. If you use a through model with custom attributes, these attributes can be set when adding / setting new associations in two ways. Consider users and projects from before with a join table that stores whether the project has been started yet:

    class UserProjects extends Model {}
    UserProjects.init({
      started: Sequelize.BOOLEAN
    }, { sequelize })
    User.hasMany(Project, { through: UserProjects })
    Project.hasMany(User, { through: UserProjects })
    jan.addProject(homework, { started: false }) // The homework project is not started yet
    jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner have been
    started

    If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:

    p1.userprojects {
      started: true
    }
    user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that.

    Similarily, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.

    user.getProjects().then(projects => {
      const p1 = projects[0]
      p1.userprojects.started // Is this project started yet?
    })

    Type parameters

    • M: Model

    • T: Model

    Parameters

    • this: ModelCtor<M>
    • target: ModelCtor<T>

      The model that will be associated with hasOne relationship

    • Optional options: HasManyOptions

      Options for the association

    Returns HasMany<M, T>

Static hasOne

  • hasOne<M, T>(this: ModelCtor<M>, target: ModelCtor<T>, options?: HasOneOptions): HasOne<M, T>
  • Creates an association between this (the source) and the provided target. The foreign key is added on the target.

    Example: User.hasOne(Profile). This will add userId to the profile table.

    Type parameters

    • M: Model

    • T: Model

    Parameters

    • this: ModelCtor<M>
    • target: ModelCtor<T>

      The model that will be associated with hasOne relationship

    • Optional options: HasOneOptions

      Options for the association

    Returns HasOne<M, T>

Static increment

  • increment<M, K>(this: { constructor: any }, field: K, options: IncrementDecrementOptionsWithBy): Promise<M>
  • increment<M, K>(this: { constructor: any }, fields: K[], options: IncrementDecrementOptionsWithBy): Promise<M>
  • increment<M, K>(this: { constructor: any }, fields: {}, options: IncrementDecrementOptions): Promise<M>
  • Increments a single field.

    Type parameters

    • M: Model

    • K: keyof M

    Parameters

    • this: { constructor: any }
      • constructor: function
        • new __type(): M
        • Returns M

    • field: K
    • options: IncrementDecrementOptionsWithBy

    Returns Promise<M>

  • Increments multiple fields by the same value.

    Type parameters

    • M: Model

    • K: keyof M

    Parameters

    • this: { constructor: any }
      • constructor: function
        • new __type(): M
        • Returns M

    • fields: K[]
    • options: IncrementDecrementOptionsWithBy

    Returns Promise<M>

  • Increments multiple fields by different values.

    Type parameters

    • M: Model

    • K: keyof M

    Parameters

    • this: { constructor: any }
      • constructor: function
        • new __type(): M
        • Returns M

    • fields: {}
    • options: IncrementDecrementOptions

    Returns Promise<M>

Static init

  • init(attributes: ModelAttributes, options: InitOptions): void
  • Parameters

    • attributes: ModelAttributes
    • options: InitOptions

    Returns void

Static logBulkCreate

  • logBulkCreate(instances: any): Promise<void>
  • Parameters

    • instances: any

    Returns Promise<void>

Static logCreate

  • logCreate(instance: any): Promise<void>
  • Parameters

    • instance: any

    Returns Promise<void>

Static logDestroy

  • logDestroy(instance: any): Promise<void>
  • Parameters

    • instance: any

    Returns Promise<void>

Static logUpdate

  • logUpdate(instance: any): Promise<void>
  • Parameters

    • instance: any

    Returns Promise<void>

Static max

  • max<M, T>(this: { constructor: any } & typeof Model, field: keyof M, options?: AggregateOptions<T>): Promise<T>
  • Find the maximum value of field

    Type parameters

    • M: Model

    • T: DataType | unknown

    Parameters

    • this: { constructor: any } & typeof Model
    • field: keyof M
    • Optional options: AggregateOptions<T>

    Returns Promise<T>

Static min

  • min<M, T>(this: { constructor: any } & typeof Model, field: keyof M, options?: AggregateOptions<T>): Promise<T>
  • Find the minimum value of field

    Type parameters

    • M: Model

    • T: DataType | unknown

    Parameters

    • this: { constructor: any } & typeof Model
    • field: keyof M
    • Optional options: AggregateOptions<T>

    Returns Promise<T>

Static removeAttribute

  • removeAttribute(attribute: string): void
  • Remove attribute from model definition

    Parameters

    • attribute: string

    Returns void

Static removeHook

  • removeHook<C, K>(hookType: K, name: string): C
  • Remove hook from the model

    Type parameters

    • C: typeof Hooks

    • K: keyof SequelizeHooks

    Parameters

    • hookType: K
    • name: string

    Returns C

Static restore

  • restore(options?: RestoreOptions): Promise<void>
  • Restore multiple instances if paranoid is enabled.

    Parameters

    • Optional options: RestoreOptions

    Returns Promise<void>

Static schema

  • schema<M>(this: { constructor: any } & typeof Model, schema: string, options?: SchemaOptions): { constructor: any } & typeof Model
  • Apply a schema to this model. For postgres, this will actually place the schema in front of the table name

    • "schema"."tableName", while the schema will be prepended to the table name for mysql and sqlite - 'schema.tablename'.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • schema: string

      The name of the schema

    • Optional options: SchemaOptions

    Returns { constructor: any } & typeof Model

Static scope

  • scope<M>(this: M, options?: string | ScopeOptions | (string | ScopeOptions)[] | WhereAttributeHash): M
  • Apply a scope created in define to the model. First let's look at how to create scopes:

    class MyModel extends Model {}
    MyModel.init(attributes, {
      defaultScope: {
        where: {
          username: 'dan'
        },
        limit: 12
      },
      scopes: {
        isALie: {
          where: {
            stuff: 'cake'
          }
        },
        complexFunction(email, accessLevel) {
          return {
            where: {
              email: {
                [Op.like]: email
              },
              accesss_level {
                [Op.gte]: accessLevel
              }
            }
          }
        }
      },
      sequelize,
    })

    Now, since you defined a default scope, every time you do Model.find, the default scope is appended to your query. Here's a couple of examples:

    Model.findAll() // WHERE username = 'dan'
    Model.findAll({ where: { age: { gt: 12 } } }) // WHERE age > 12 AND username = 'dan'

    To invoke scope functions you can do:

    Model.scope({ method: ['complexFunction' 'dan@sequelize.com', 42]}).findAll()
    // WHERE email like 'dan@sequelize.com%' AND access_level >= 42

    Type parameters

    • M: { constructor: any }

    Parameters

    • this: M
    • Optional options: string | ScopeOptions | (string | ScopeOptions)[] | WhereAttributeHash

    Returns M

    Model A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.

Static sum

  • sum<M, T>(this: { constructor: any } & typeof Model, field: keyof M, options?: AggregateOptions<T>): Promise<number>
  • Find the sum of field

    Type parameters

    • M: Model

    • T: DataType | unknown

    Parameters

    • this: { constructor: any } & typeof Model
    • field: keyof M
    • Optional options: AggregateOptions<T>

    Returns Promise<number>

Static sync

  • sync(options?: SyncOptions): Promise<Model>
  • Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)

    Parameters

    • Optional options: SyncOptions

    Returns Promise<Model>

Static truncate

  • truncate(options?: TruncateOptions): Promise<void>
  • Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }).

    Parameters

    • Optional options: TruncateOptions

    Returns Promise<void>

Static unscoped

  • unscoped<M>(this: M): M
  • Unscope the model

    Type parameters

    • M: typeof Model

    Parameters

    • this: M

    Returns M

Static update

  • update<M>(this: { constructor: any } & typeof Model, values: object, options: UpdateOptions): Promise<[number, M[]]>
  • Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number of affected rows, while the second element is the actual affected rows (only supported in postgres and mssql with options.returning true.)

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • values: object
    • options: UpdateOptions

    Returns Promise<[number, M[]]>

Static upsert

  • upsert<M>(this: { constructor: any } & typeof Model, values: object, options?: UpsertOptions & { returning?: false | undefined }): Promise<boolean>
  • upsert<M>(this: { constructor: any } & typeof Model, values: object, options?: UpsertOptions & { returning: true }): Promise<[M, boolean]>
  • Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found. Note that the unique index must be defined in your sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.

    Implementation details:

    • MySQL - Implemented as a single query INSERT values ON DUPLICATE KEY UPDATE values
    • PostgreSQL - Implemented as a temporary function with exception handling: INSERT EXCEPTION WHEN unique_constraint UPDATE
    • SQLite - Implemented as two queries INSERT; UPDATE. This means that the update is executed regardless of whether the row already existed or not

    Note that SQLite returns undefined for created, no matter if the row was created or updated. This is because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know whether the row was inserted or not.

    Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • values: object
    • Optional options: UpsertOptions & { returning?: false | undefined }

    Returns Promise<boolean>

  • Type parameters

    • M: Model

    Parameters

    • this: { constructor: any } & typeof Model
    • values: object
    • Optional options: UpsertOptions & { returning: true }

    Returns Promise<[M, boolean]>

Generated using TypeDoc