# Sequelize class · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-sequelize 4.2.0 — generated reference, not hand-written

Sequelize's own connection class, taught about views, column indices and the widened `returning` option.

**Signature:**

```typescript
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


```typescript
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)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.define/) |  | Defines a model from an attribute map rather than from a decorated class. |
| [getModelsWithIndices()](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.getmodelswithindices/) |  | The registered models that declare at least one column index. |
| [getQueryInterface()](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.getqueryinterface/) |  | The query interface for this connection, with view support and the widened `returning` option. |
| [getViews()](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.getviews/) |  | The registered models that are declared as views. |
| [query(sqlQuery, options)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.query/) |  | Runs a raw statement, honouring a `returning` column list. |
| [sync(options)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.sync/) |  | Creates every table, then every view, then every column index. |
| [syncIndices(options)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.syncindices/) |  | Creates the column indices declared across every registered model. |
| [syncViews(options)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.sequelize.syncviews/) |  | Replaces every model that is declared as a view. |

