$ open source · GPL-3.0 — need a commercial license? imqueue.com →

Sequelize class

Sequelize's own connection class, taught about views, column indices and the widened returning option.

Signature:

export declare class Sequelize extends SequelizeOrigin 

Extends: SequelizeOrigin

Remarks

Returned by database(), which is how a service normally gets one. Four things differ from the class it extends.

Views are first-class: a model declared with View or DynamicView is created as a view after every table exists, dropped as a view, and skipped by the table sync. A dynamic view goes further — its definition carries @{name} placeholders, and the select-query generator substitutes them into the statement at query time, so one model can be read with different parameters, including when it is reached through a join.

Column indices declared with ColumnIndex or NullableIndex are created as part of the same sync, which sequelize has no notion of at all.

returning may name columns rather than being a boolean, both on the write methods and on a raw query().

Example

const orm = database(dbConfig);       // a Sequelize, already connected

await orm.sync();                     // tables, then views, then indices
await orm.sync({ withNoViews: true }); // tables and indices only

Methods

Method

Modifiers

Description

define(modelName, attributes, options)

Defines a model from an attribute map rather than from a decorated class.

getModelsWithIndices()

The registered models that declare at least one column index.

getQueryInterface()

The query interface for this connection, with view support and the widened returning option.

getViews()

The registered models that are declared as views.

query(sqlQuery, options)

Runs a raw statement, honouring a returning column list.

sync(options)

Creates every table, then every view, then every column index.

syncIndices(options)

Creates the column indices declared across every registered model.

syncViews(options)

Replaces every model that is declared as a view.