Class QueryInterface

The interface that Sequelize uses to talk to all databases.

This interface is available through sequelize.queryInterface. It should not be commonly used, but it's referenced anyway, so it can be used.

Hierarchy

  • QueryInterface

Constructors

Properties

queryGenerator: AbstractQueryGenerator

Returns the dialect-specific sql generator.

We don't have a definition for the QueryGenerator, because I doubt it is commonly in use separately.

sequelize: Sequelize

Returns the current sequelize instance.

Methods

  • Adds constraints to a table

    Parameters

    • tableName: TableName
    • Optional options: Object

    Returns Promise<void>

  • Adds a new index to a table

    Parameters

    Returns Promise<void>

  • Parameters

    • tableName: TableName
    • options: {
          benchmark?: boolean;
          bind?: BindOrReplacements;
          concurrently?: boolean;
          fieldMap?: FieldMap;
          fields: (string | Fn | Literal | IndexField)[];
          instance?: Model<any, any>;
          logging?: boolean | ((sql: string, timing?: number) => void);
          mapToModel?: boolean;
          name?: string;
          nest?: boolean;
          operator?: string;
          parser?: null | string;
          plain?: boolean;
          prefix?: string;
          raw?: boolean;
          replacements?: {
              [key: string]: unknown;
          };
          retry?: RetryOptions;
          transaction?: null | Transaction;
          type?: IndexType;
          unique?: boolean;
          useMaster?: boolean;
          using?: string;
          where?: WhereOptions<any>;
      }
      • Optional benchmark?: boolean

        Pass query execution time in milliseconds as second argument to logging function (options.logging).

      • Optional bind?: BindOrReplacements

        Either an object of named parameter bindings in the format $param or an array of unnamed values to bind to $1, $2, etc in your SQL.

      • Optional concurrently?: boolean

        PostgreSQL will build the index without taking any write locks. Postgres only.

        Default

        false

      • Optional fieldMap?: FieldMap

        Map returned fields to arbitrary names for SELECT query type if options.fieldMaps is present.

      • fields: (string | Fn | Literal | IndexField)[]

        The fields to index.

      • Optional instance?: Model<any, any>

        A sequelize instance used to build the return instance

      • Optional logging?: boolean | ((sql: string, timing?: number) => void)

        A function that gets executed while running the query to log the sql.

      • Optional mapToModel?: boolean

        Map returned fields to model's fields if options.model or options.instance is present. Mapping will occur before building the model instance.

      • Optional name?: string

        The name of the index. Defaults to model name + _ + fields concatenated

      • Optional nest?: boolean

        If true, transforms objects with . separated property names into nested objects using dottie.js. For example { 'user.username': 'john' } becomes { user: { username: 'john' }}. When nest is true, the query type is assumed to be 'SELECT', unless otherwise specified

        Default

        false

      • Optional operator?: string

        Index operator type. Postgres only

      • Optional parser?: null | string

        For FULLTEXT columns set your parser

      • Optional plain?: boolean

        Sets the query type to SELECT and return a single row

      • Optional prefix?: string

        Prefix to append to the index name.

      • Optional raw?: boolean

        If true, sequelize will not try to format the results of the query, or build an instance of a model from the result

      • Optional replacements?: {
            [key: string]: unknown;
        }

        Only named replacements are allowed in query interface methods.

        • [key: string]: unknown
      • Optional retry?: RetryOptions
      • Optional transaction?: null | Transaction

        The transaction in which this query must be run.

        If CLS is enabled and a transaction is running in the current CLS context, that transaction will be used, unless null or a Transaction is manually specified here.

      • Optional type?: IndexType

        Index type. Only used by mysql. One of UNIQUE, FULLTEXT and SPATIAL

      • Optional unique?: boolean

        Should the index by unique? Can also be triggered by setting type to UNIQUE

        Default

        false

      • Optional useMaster?: boolean

        Force the query to use the write pool, regardless of the query type.

        Default

        false

      • Optional using?: string

        The method to create the index by (USING statement in SQL). BTREE and HASH are supported by mysql and postgres. Postgres additionally supports GIST, SPGIST, BRIN and GIN.

      • Optional where?: WhereOptions<any>

        Optional where parameter for index. Can be used to limit the index to certain rows.

    • Optional rawTablename: string

    Returns Promise<void>

  • Commit an already started transaction

    Parameters

    Returns Promise<void>

  • Creates a database

    Parameters

    Returns Promise<void>

  • Postgres only. Create a function

    Parameters

    Returns Promise<void>

  • Queries the schema (table list).

    Parameters

    • Optional schema: string

      The schema to query. Applies only to Postgres.

    • Optional options: QueryRawOptions

    Returns Promise<void>

  • Postgres only. Creates a trigger on specified table to call the specified function with supplied parameters.

    Parameters

    Returns Promise<void>

  • Return database version

    Parameters

    Returns Promise<string>

  • Describe a table

    Parameters

    • tableName: TableName
    • Optional options: string | {
          schema?: string;
          schemaDelimiter?: string;
      } & Logging

    Returns Promise<ColumnsDescription>

  • Drops all defined enums

    Parameters

    Returns Promise<void>

  • Creates a database

    Parameters

    Returns Promise<void>

  • Drops the specified schema (table).

    Parameters

    • Optional schema: string

      The schema to query. Applies only to Postgres.

    • Optional options: QueryRawOptions

    Returns Promise<void>

  • Get foreign key references details for the table

    Parameters

    Returns Promise<object>

  • Returns all foreign key constraints of requested tables

    Parameters

    Returns Promise<object>

  • Inserts a new record

    Parameters

    • instance: null | Model<any, any>
    • tableName: string
    • values: object
    • Optional options: QiInsertOptions

    Returns Promise<object>

  • Put a name to an index

    Parameters

    • indexes: string[]
    • rawTablename: string

    Returns Promise<void>

  • Escape an identifier (e.g. a table or attribute name). If force is true, the identifier will be quoted even if the quoteIdentifiers option is false.

    Parameters

    • identifier: string
    • Optional force: boolean

    Returns string

  • Split an identifier into .-separated tokens and quote each part.

    Parameters

    • identifiers: string

    Returns string

  • Selects raw without parsing the string into an object

    Parameters

    Returns Promise<string[]>

  • Removes constraints from a table

    Parameters

    Returns Promise<void>

  • Renames a column

    Parameters

    Returns Promise<void>

  • Postgres only. Rename a function

    Parameters

    Returns Promise<void>

  • Postgres only. Renames a trigger

    Parameters

    Returns Promise<void>

  • Rollback ( revert ) a transaction that has'nt been commited

    Parameters

    Returns Promise<void>

  • Set option for autocommit of a transaction

    Parameters

    Returns Promise<void>

  • Set the isolation level of a transaction

    Parameters

    Returns Promise<void>

  • Queries all table names in the database.

    Parameters

    Returns Promise<object>

  • Returns all tables

    Parameters

    Returns Promise<string[]>

  • Shows the index of a table

    Parameters

    Returns Promise<object>

  • Begin a new transaction

    Parameters

    Returns Promise<void>

  • Returns a promise that resolves to true if the table exists in the database, false otherwise.

    Parameters

    Returns Promise<boolean>

  • Inserts or Updates a record in the database

    Type Parameters

    • M extends Model<any, any, M>

    Parameters

    Returns Promise<object>

Generated using TypeDoc