Documentation
    Preparing search index...

    Class AbstractQueryInterfaceTypeScript<Dialect>

    This is a temporary class used to progressively migrate the AbstractQueryInterface class to TypeScript by slowly moving its functions here. Always use AbstractQueryInterface instead.

    Type Parameters

    Hierarchy (View Summary)

    Index
    dialect: Dialect
    • get queryGenerator(): Dialect["queryGenerator"]

      Returns Dialect["queryGenerator"]

    • Add a constraint to a table

      Available constraints:

      • UNIQUE
      • DEFAULT (MSSQL only)
      • CHECK (Not supported by MySQL)
      • FOREIGN KEY
      • PRIMARY KEY

      Parameters

      Returns Promise<void>

      queryInterface.addConstraint('Users', {
      fields: ['email'],
      type: 'UNIQUE',
      name: 'custom_unique_constraint_name'
      });
      queryInterface.addConstraint('Users', {
      fields: ['roles'],
      type: 'CHECK',
      where: {
      roles: ['user', 'admin', 'moderator', 'guest']
      }
      });
      queryInterface.addConstraint('Users', {
      fields: ['roles'],
      type: 'DEFAULT',
      defaultValue: 'guest'
      });
      queryInterface.addConstraint('Users', {
      fields: ['username'],
      type: 'PRIMARY KEY',
      name: 'custom_primary_constraint_name'
      });
      queryInterface.addConstraint('Users', {
      fields: ['first_name', 'last_name'],
      type: 'PRIMARY KEY',
      name: 'custom_primary_constraint_name'
      });
      queryInterface.addConstraint('Posts', {
      fields: ['username'],
      type: 'FOREIGN KEY',
      name: 'custom_fkey_constraint_name',
      references: { //Required field
      table: 'target_table_name',
      field: 'target_column_name'
      },
      onDelete: 'cascade',
      onUpdate: 'cascade'
      });
      queryInterface.addConstraint('TableName', {
      fields: ['source_column_name', 'other_source_column_name'],
      type: 'FOREIGN KEY',
      name: 'custom_fkey_constraint_name',
      references: { //Required field
      table: 'target_table_name',
      fields: ['target_column_name', 'other_target_column_name']
      },
      onDelete: 'cascade',
      onUpdate: 'cascade'
      });
    • Create a new database schema.

      Note: We define schemas as a namespace that can contain tables. In mysql and mariadb, this command will create what they call a database.

      Parameters

      Returns Promise<void>

    • Describe a table structure

      This method returns an array of hashes containing information about all attributes in the table.

      {
      name: {
      type: 'VARCHAR(255)', // this will be 'CHARACTER VARYING' for pg!
      allowNull: true,
      defaultValue: null
      },
      isBetaMember: {
      type: 'TINYINT(1)', // this will be 'BOOLEAN' for pg!
      allowNull: false,
      defaultValue: false
      }
      }

      Parameters

      Returns Promise<ColumnsDescription>

    • Drop a database

      Parameters

      Returns Promise<void>

    • Drop a single schema

      Note: We define schemas as a namespace that can contain tables. In mysql and mariadb, this command will create what they call a database.

      Parameters

      Returns Promise<void>

    • Remove a constraint from a table

      Parameters

      Returns Promise<void>

    • Returns a promise that will resolve to true if the table or model exists in the database, false otherwise.

      Parameters

      Returns Promise<boolean>

    • Toggles foreign key checks. Don't forget to turn them back on, use withoutForeignKeyChecks to do this automatically.

      Parameters

      Returns Promise<void>

    • Disables foreign key checks for the duration of the callback. The foreign key checks are only disabled for the current connection. To specify the connection, you can either use the "connection" or the "transaction" option. If you do not specify a connection, this method will reserve a connection for the duration of the callback, and release it afterwards. You will receive the connection or transaction as the first argument of the callback. You must use this connection to execute queries

      Type Parameters

      • T

      Returns Promise<T>

      await this.queryInterface.withoutForeignKeyChecks(options, async connection => {
      const truncateOptions = { ...options, connection };

      for (const model of models) {
      await model.truncate(truncateOptions);
      }
      });
    • Disables foreign key checks for the duration of the callback. The foreign key checks are only disabled for the current connection. To specify the connection, you can either use the "connection" or the "transaction" option. If you do not specify a connection, this method will reserve a connection for the duration of the callback, and release it afterwards. You will receive the connection or transaction as the first argument of the callback. You must use this connection to execute queries

      Type Parameters

      • T

      Returns Promise<T>

      await this.queryInterface.withoutForeignKeyChecks(options, async connection => {
      const truncateOptions = { ...options, connection };

      for (const model of models) {
      await model.truncate(truncateOptions);
      }
      });