The dialect instance.
Optional
internalQueryInterface: AbstractQueryInterfaceInternalThe internal query interface to use. Defaults to a new instance of AbstractQueryInterfaceInternal. Your dialect may replace this with a custom implementation.
Private
Readonly
#internalReadonly
dialectPrivate
#withoutCommit an already started transaction.
This is an internal method used by sequelize.transaction()
use at your own risk.
Create a new savepoint.
This is an internal method used by sequelize.transaction()
use at your own risk.
Rollback to a savepoint.
This is an internal method used by sequelize.transaction()
use at your own risk.
Rollback (revert) a transaction that hasn't been committed.
This is an internal method used by sequelize.transaction()
use at your own risk.
Set the isolation level of a transaction.
This is an internal method used by sequelize.transaction()
use at your own risk.
Begin a new transaction.
This is an internal method used by sequelize.transaction()
use at your own risk.
Adds a new column to a table
Optional
options: AddColumnOptionsAdd a constraint to a table
Available constraints:
Table name where you want to add a constraint
An object to define the constraint name, type etc
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'
});
Adds a new index to a table
Optional
options: QueryInterfaceIndexOptionsOptional
rawTablename: stringPrivate
Optional
[COMPLETES_Indicates if the query completes the transaction Internal only
Optional
benchmark?: booleanPass query execution time in milliseconds as second argument to logging function (options.logging).
Optional
bind?: BindOrReplacementsEither 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?: booleanPostgreSQL will build the index without taking any write locks. Postgres only.
false
Optional
connection?: null | AbstractConnectionThe connection on which this query must be run. Mutually exclusive with Transactionable.transaction.
Can be used to ensure that a query is run on the same connection as a previous query, which is useful when configuring session options.
Specifying this option takes precedence over CLS Transactions. If a transaction is running in the current AsyncLocalStorage context, it will be ignored in favor of the specified connection.
Optional
fieldMap returned fields to arbitrary names for SELECT query type if options.fieldMaps
is present.
The fields to index.
Optional
include?: Literal | (string | Literal)[]Non-key columns to be added to the lead level of the nonclustered index.
Optional
instance?: Model<any, any>A sequelize instance used to build the return instance
Optional
logging?: false | ((sql, timing?) => void)A function that gets executed while running the query to log the sql.
Optional
mapMap returned fields to model's fields if options.model
or options.instance
is present.
Mapping will occur before building the model instance.
Optional
msg?: stringThe message to display if the unique constraint is violated.
Optional
name?: stringThe name of the index. Defaults to model name + _ + fields concatenated
Optional
nest?: booleanIf 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
false
Optional
operator?: stringIndex operator type. Postgres only
Optional
parser?: null | stringFor FULLTEXT columns set your parser
Optional
plain?: booleanSets the query type to SELECT
and return a single row
Optional
prefix?: stringPrefix to append to the index name.
Optional
raw?: booleanIf true, sequelize will not try to format the results of the query, or build an instance of a model from the result
Optional
replacements?: { Only named replacements are allowed in query interface methods.
Optional
retry?: OptionsOptional
supportsIf false do not prepend the query with the search_path (Postgres only)
Optional
transaction?: null | TransactionThe transaction in which this query must be run. Mutually exclusive with Transactionable.connection.
If the Sequelize disableClsTransactions option has not been set to true, and a transaction is running in the current AsyncLocalStorage context, that transaction will be used, unless null or another Transaction is manually specified here.
Optional
type?: IndexTypeIndex type. Only used by mysql. One of UNIQUE
, FULLTEXT
and SPATIAL
Optional
unique?: booleanShould the index by unique? Can also be triggered by setting type to UNIQUE
false
Optional
useForce the query to use the write pool, regardless of the query type.
false
Optional
using?: stringThe 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?: WhereOptionsOptional where parameter for index. Can be used to limit the index to certain rows.
Optional
rawTablename: stringOptional
options: QueryRawOptionsDeletes records from a table
Optional
options: QiBulkDeleteOptions<any>Inserts multiple records at once
Optional
options: QiOptionsWithReplacementsOptional
attributes: Record<string, AttributeOptions<Model<any, any>>>Updates multiple rows at once
Optional
options: QiOptionsWithReplacementsOptional
columnDefinitions: { Changes a column
Optional
dataTypeOrOptions: DataType | AttributeOptions<Model<any, any>>Optional
options: QiOptionsWithReplacementsCreate a database
Optional
options: CreateDatabaseOptionsPostgres only. Create a function
Optional
optionsArray: string[]Optional
options: CreateFunctionOptionsCreate 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.
Name of the schema
Optional
options: CreateSchemaOptionsCreates a table with specified attributes.
Name of table to create
Hash of attributes, key is attribute name, value is data type
Optional
options: QueryInterfaceCreateTableOptionsTable options.
Postgres only. Creates a trigger on specified table to call the specified function with supplied parameters.
Optional
options: QiOptionsWithReplacementsDecrements a row value
Optional
options: QiArithmeticOptionsOptional
options: DeferConstraintsOptionsDescribe 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
}
}
Optional
options: DescribeTableOptionsQuery options
Drops all defined enums
Optional
options: QueryRawOptionsDrops all schemas
Optional
options: QiDropAllSchemasOptionsDrop all tables
Optional
options: QiDropAllTablesOptionsDrop a database
Optional
options: QueryRawOptionsPostgres only. Drops a function
Optional
options: QiOptionsWithReplacementsDrop 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.
Name of the schema
Optional
options: DropSchemaOptionsDrop a table from database
Table name to drop
Optional
options: QiDropTableOptionsQuery options
Postgres only. Drops the specified trigger.
Optional
options: QiOptionsWithReplacementsReturns the database version.
Optional
options: FetchDatabaseVersionOptionsQuery Options
Get foreign key references details for the table
Optional
_options: QueryRawOptionsUse showConstraints instead.
Returns all foreign key constraints of requested tables
Optional
_options: QueryRawOptionsUse showConstraints instead.
Increments a row value
Optional
options: QiArithmeticOptionsInserts a new record
Optional
options: QiInsertOptionsLists all available databases
Optional
options: ListDatabasesOptionsList defined schemas
Note: this is a schema in the postgres sense of the word, not a database table. In mysql and mariadb, this will show all databases.
Optional
options: QiListSchemasOptionslist of schemas
List tables
Optional
options: QiListTablesOptionsSelects raw without parsing the string into an object
Optional
model: ModelStaticRemoves a column from a table
Optional
options: RemoveColumnOptionsRemove a constraint from a table
Table name to drop constraint from
Constraint name
Optional
options: RemoveConstraintOptionsQuery options
Removes an index of a table
Optional
options: QueryInterfaceRemoveIndexOptionsOptional
options: QueryInterfaceRemoveIndexOptionsRenames a column
Optional
options: QiOptionsWithReplacementsPostgres only. Rename a function
Optional
options: QiOptionsWithReplacementsRename a table
Optional
options: RenameTableOptionsPostgres only. Renames a trigger
Optional
options: QiOptionsWithReplacementsReturns selected rows
Optional
options: QiSelectOptionsShow all defined schemas
Optional
options: QiListSchemasOptionsUse listSchemas instead.
Show all tables
Optional
options: QiListTablesOptionsUse listTables instead.
Optional
options: ShowConstraintsOptionsShows the index of a table
Optional
options: QueryRawOptionsReturns a promise that will resolve to true if the table or model exists in the database, false otherwise.
The name of the table or model
Optional
options: QueryRawOptionsQuery options
Truncates a table
Optional
options: QiTruncateTableOptionsToggles foreign key checks. Don't forget to turn them back on, use withoutForeignKeyChecks to do this automatically.
Optional
options: QueryRawOptionsUpdates a row
Optional
options: QiUpdateOptionsInserts or Updates a record in the database
Optional
options: QiUpsertOptions<M>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
await this.queryInterface.withoutForeignKeyChecks(options, async connection => {
const truncateOptions = { ...options, connection };
for (const model of models) {
await model.truncate(truncateOptions);
}
});
This interface exposes low-level APIs to interact with the database. Typically useful in contexts where models are not available, such as migrations.
This interface is available through Sequelize#queryInterface.