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.
Add 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'
});
Deletes records from a table
Optional
options: QiBulkDeleteOptions<any>Create a database
Optional
options: CreateDatabaseOptionsCreate 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: CreateSchemaOptionsOptional
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 schemas
Optional
options: QiDropAllSchemasOptionsDrop all tables
Optional
options: QiDropAllTablesOptionsDrop a database
Optional
options: QueryRawOptionsDrop 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
Returns 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.
Lists 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: QiListTablesOptionsRemoves 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
Rename a table
Optional
options: RenameTableOptionsShow all defined schemas
Optional
options: QiListSchemasOptionsUse listSchemas instead.
Show all tables
Optional
options: QiListTablesOptionsUse listTables instead.
Optional
options: ShowConstraintsOptionsReturns 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: QueryRawOptionsDisables 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 is a temporary class used to progressively migrate the AbstractQueryInterface class to TypeScript by slowly moving its functions here. Always use AbstractQueryInterface instead.