Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 2x 13x 13x 799x | import * as errorClasses from './errors/errors.ts';
import { Association } from './associations/association.ts';
import { BelongsTo } from './associations/belongs-to.ts';
import { BelongsToMany } from './associations/belongs-to-many.ts';
import { HasMany } from './associations/has-many.ts';
import { HasOne } from './associations/has-one.ts';
import { Deferrable } from './ddl/ddl-generator.ts';
import { and, or } from './expressions/logic.ts';
import { useInflection } from './model/inflector.ts';
import { PackageVersion } from './package-version.ts';
import { QueryInterface } from './query-interface/query-interface.ts';
import validatorJs from 'validator';
import { DataTypes } from './data-types/data-types.ts';
import { cast, col, fn, json, literal, where } from './expressions/methods.ts';
import { Op } from './expressions/op.ts';
import { Model } from './model/model.ts';
import type { RuntimeOwner } from './model/runtime.ts';
import { QueryTypes } from './query/query-result-shaper.ts';
import { SequelizeBase } from './sequelize/sequelize-base.ts';
import type { InstanceHookAdders } from './sequelize/instance-hook-adders.ts';
import { SequelizeStaticHooks } from './sequelize/sequelize-static-hooks.ts';
import { SequelizeHooks } from './sequelize/sequelize-hooks.ts';
import { SequelizeNotifications } from './sequelize/sequelize-notifications.ts';
import { SequelizeHelpers } from './sequelize/sequelize-helpers.ts';
import { SequelizeSchema } from './sequelize/sequelize-schema.ts';
import { SequelizeTransactions } from './sequelize/sequelize-transactions.ts';
import type { SequelizeOptions } from './connection/options.ts';
import { Transaction } from './transaction/transaction.ts';
import { Utils } from './utils-namespace.ts';
import { transactionScope } from './transaction/transaction-runner.ts';
export { QueryTypes } from './query/query-result-shaper.ts';
export type {
QueryOptions,
QueryOptionsWithModel,
QueryOptionsWithType,
QueryType,
TypedQueryResults,
} from './query/query-result-shaper.ts';
export type { DefineOptions } from './sequelize/sequelize-base.ts';
/**
* Options of the `Sequelize` constructor (Sequelize v6 `Options`); same as {@link SequelizeOptions}.
*
* @example
* ```ts
* const options: Options = { dialect: 'postgres', logging: false };
* const sequelize = new Sequelize('postgres://localhost/app', options);
* ```
*/
export type Options = SequelizeOptions;
const packageVersion = new PackageVersion();
const SequelizeMembers = SequelizeNotifications(
SequelizeTransactions(
SequelizeSchema(SequelizeHelpers(SequelizeStaticHooks(SequelizeHooks(SequelizeBase)))),
),
);
// Declaration files cannot name the symbol key of a class member, so `RuntimeOwner` is merged in as an interface.
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- intentional merge.
export interface Sequelize extends RuntimeOwner, InstanceHookAdders {}
/**
* Entry point, API-compatible with Sequelize v6 `Sequelize` for PostgreSQL.
*
* @example
* ```ts
* const sequelize = new Sequelize('postgres://user:pass@localhost:5432/app', { logging: false });
* ```
*/
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- see the interface above.
export class Sequelize extends SequelizeMembers {
/** Column types. */
static readonly DataTypes = DataTypes;
/** Query operators. */
static readonly Op: typeof Op = Op;
/** Result shapes accepted by the `type` option of {@link Sequelize.query}, e.g. `QueryTypes.SELECT`. */
static readonly QueryTypes = QueryTypes;
/** Transaction class. */
static readonly Transaction = Transaction;
/** Model base class. */
static readonly Model = Model;
/** Raw SQL fragment builder. */
static readonly literal = literal;
/** SQL function call builder. */
static readonly fn = fn;
/** Column reference builder. */
static readonly col = col;
/** Type cast builder. */
static readonly cast = cast;
/** Comparison builder. */
static readonly where = where;
/** JSON path builder. */
static readonly json = json;
/** Subset of the v6 `Utils` helpers, see {@link Utils}. */
static readonly Utils = Utils;
// Sequelize v6 static aliases of the DataTypes and the error classes.
/** Alias of `DataTypes.ARRAY`. */
static readonly ARRAY = DataTypes.ARRAY;
/** Alias of `DataTypes.BIGINT`. */
static readonly BIGINT = DataTypes.BIGINT;
/** Alias of `DataTypes.BLOB`. */
static readonly BLOB = DataTypes.BLOB;
/** Alias of `DataTypes.BOOLEAN`. */
static readonly BOOLEAN = DataTypes.BOOLEAN;
/** Alias of `DataTypes.CHAR`. */
static readonly CHAR = DataTypes.CHAR;
/** Alias of `DataTypes.CIDR`. */
static readonly CIDR = DataTypes.CIDR;
/** Alias of `DataTypes.CITEXT`. */
static readonly CITEXT = DataTypes.CITEXT;
/** Alias of `DataTypes.DATE`. */
static readonly DATE = DataTypes.DATE;
/** Alias of `DataTypes.DATEONLY`. */
static readonly DATEONLY = DataTypes.DATEONLY;
/** Alias of `DataTypes.DECIMAL`. */
static readonly DECIMAL = DataTypes.DECIMAL;
/** Alias of `DataTypes.DOUBLE`. */
static readonly DOUBLE = DataTypes.DOUBLE;
/** Alias of `DataTypes.ENUM`. */
static readonly ENUM = DataTypes.ENUM;
/** Alias of `DataTypes.FLOAT`. */
static readonly FLOAT = DataTypes.FLOAT;
/** Alias of `DataTypes.GEOGRAPHY`. */
static readonly GEOGRAPHY = DataTypes.GEOGRAPHY;
/** Alias of `DataTypes.GEOMETRY`. */
static readonly GEOMETRY = DataTypes.GEOMETRY;
/** Alias of `DataTypes.HSTORE`. */
static readonly HSTORE = DataTypes.HSTORE;
/** Alias of `DataTypes.INET`. */
static readonly INET = DataTypes.INET;
/** Alias of `DataTypes.INTEGER`. */
static readonly INTEGER = DataTypes.INTEGER;
/** Alias of `DataTypes.JSON`. */
static readonly JSON = DataTypes.JSON;
/** Alias of `DataTypes.JSONB`. */
static readonly JSONB = DataTypes.JSONB;
/** Alias of `DataTypes.MACADDR`. */
static readonly MACADDR = DataTypes.MACADDR;
/** Alias of `DataTypes.MEDIUMINT`. */
static readonly MEDIUMINT = DataTypes.MEDIUMINT;
/** Alias of `DataTypes.NOW`. */
static readonly NOW = DataTypes.NOW;
/** Alias of `DataTypes.NUMBER`. */
static readonly NUMBER = DataTypes.NUMBER;
/** Alias of `DataTypes.NUMERIC`. */
static readonly NUMERIC = DataTypes.NUMERIC;
/** Alias of `DataTypes.RANGE`. */
static readonly RANGE = DataTypes.RANGE;
/** Alias of `DataTypes.REAL`. */
static readonly REAL = DataTypes.REAL;
/** Alias of `DataTypes.SMALLINT`. */
static readonly SMALLINT = DataTypes.SMALLINT;
/** Alias of `DataTypes.STRING`. */
static readonly STRING = DataTypes.STRING;
/** Alias of `DataTypes.TEXT`. */
static readonly TEXT = DataTypes.TEXT;
/** Alias of `DataTypes.TIME`. */
static readonly TIME = DataTypes.TIME;
/** Alias of `DataTypes.TINYINT`. */
static readonly TINYINT = DataTypes.TINYINT;
/** Alias of `DataTypes.TSVECTOR`. */
static readonly TSVECTOR = DataTypes.TSVECTOR;
/** Alias of `DataTypes.UUID`. */
static readonly UUID = DataTypes.UUID;
/** Alias of `DataTypes.UUIDV4`. */
static readonly UUIDV4 = DataTypes.UUIDV4;
/** Alias of `DataTypes.VIRTUAL`. */
static readonly VIRTUAL = DataTypes.VIRTUAL;
/** Alias of `DataTypes.DOUBLE`. */
static readonly 'DOUBLE PRECISION' = DataTypes['DOUBLE PRECISION'];
/** Alias of the exported `AccessDeniedError`. */
static readonly AccessDeniedError = errorClasses.AccessDeniedError;
/** Alias of the exported `AggregateError`. */
static readonly AggregateError = errorClasses.AggregateError;
/** Alias of the exported `AssociationError`. */
static readonly AssociationError = errorClasses.AssociationError;
/** Alias of the exported `BaseError`. */
static readonly BaseError = errorClasses.BaseError;
/** Alias of the exported `BulkRecordError`. */
static readonly BulkRecordError = errorClasses.BulkRecordError;
/** Alias of the exported `ConnectionAcquireTimeoutError`. */
static readonly ConnectionAcquireTimeoutError = errorClasses.ConnectionAcquireTimeoutError;
/** Alias of the exported `ConnectionError`. */
static readonly ConnectionError = errorClasses.ConnectionError;
/** Alias of the exported `ConnectionRefusedError`. */
static readonly ConnectionRefusedError = errorClasses.ConnectionRefusedError;
/** Alias of the exported `ConnectionTimedOutError`. */
static readonly ConnectionTimedOutError = errorClasses.ConnectionTimedOutError;
/** Alias of the exported `DatabaseError`. */
static readonly DatabaseError = errorClasses.DatabaseError;
/** Alias of the exported `EagerLoadingError`. */
static readonly EagerLoadingError = errorClasses.EagerLoadingError;
/** Alias of the exported `EmptyResultError`. */
static readonly EmptyResultError = errorClasses.EmptyResultError;
/** Alias of the exported `ExclusionConstraintError`. */
static readonly ExclusionConstraintError = errorClasses.ExclusionConstraintError;
/** Alias of the exported `ForeignKeyConstraintError`. */
static readonly ForeignKeyConstraintError = errorClasses.ForeignKeyConstraintError;
/** Alias of the exported `HostNotFoundError`. */
static readonly HostNotFoundError = errorClasses.HostNotFoundError;
/** Alias of the exported `HostNotReachableError`. */
static readonly HostNotReachableError = errorClasses.HostNotReachableError;
/** Alias of the exported `InstanceError`. */
static readonly InstanceError = errorClasses.InstanceError;
/** Alias of the exported `InvalidConnectionError`. */
static readonly InvalidConnectionError = errorClasses.InvalidConnectionError;
/** Alias of the exported `OptimisticLockError`. */
static readonly OptimisticLockError = errorClasses.OptimisticLockError;
/** Alias of the exported `QueryError`. */
static readonly QueryError = errorClasses.QueryError;
/** Alias of the exported `SequelizeScopeError`. */
static readonly SequelizeScopeError = errorClasses.SequelizeScopeError;
/** Alias of the exported `TimeoutError`. */
static readonly TimeoutError = errorClasses.TimeoutError;
/** Alias of the exported `UniqueConstraintError`. */
static readonly UniqueConstraintError = errorClasses.UniqueConstraintError;
/** Alias of the exported `UnknownConstraintError`. */
static readonly UnknownConstraintError = errorClasses.UnknownConstraintError;
/** Alias of the exported `ValidationError`. */
static readonly ValidationError = errorClasses.ValidationError;
/** Alias of the exported `ValidationErrorItem`. */
static readonly ValidationErrorItem = errorClasses.ValidationErrorItem;
/** Alias of the exported `ValidationErrorItemOrigin`. */
static readonly ValidationErrorItemOrigin = errorClasses.ValidationErrorItemOrigin;
/** Alias of the exported `ValidationErrorItemType`. */
static readonly ValidationErrorItemType = errorClasses.ValidationErrorItemType;
/** Alias of `BaseError`. */
static readonly Error = errorClasses.BaseError;
/** `Deferrable` constraint modes. */
static readonly Deferrable = Deferrable;
/** Base class of the association classes. */
static readonly Association = Association;
/** `hasOne` association class. */
static readonly HasOne = HasOne;
/** `hasMany` association class. */
static readonly HasMany = HasMany;
/** `belongsTo` association class. */
static readonly BelongsTo = BelongsTo;
/** `belongsToMany` association class. */
static readonly BelongsToMany = BelongsToMany;
/** Schema API class. */
static readonly QueryInterface = QueryInterface;
/** The `validator` library used by the built-in validators. */
static readonly Validator = validatorJs;
/** Combines conditions with `AND`. */
static readonly and = and;
/** Combines conditions with `OR`. */
static readonly or = or;
/** Replaces the inflection library, see {@link useInflection}. */
static readonly useInflection = useInflection;
/**
* Version of the installed postgrelize package (Sequelize v6 `Sequelize.version` reports its own version).
*
* @returns Semver string, e.g. `'1.1.0'`.
*/
static get version(): string {
return packageVersion.read();
}
/**
* Enables continuation-local transactions: queries inside `sequelize.transaction(fn)` use the
* transaction automatically. Without an argument `AsyncLocalStorage` is used. With a `cls-hooked`
* style namespace (an object with `bind`, `run`, `get` and `set`) it behaves as in Sequelize v6:
* managed transactions run in `namespace.run` and store themselves under `namespace.get('transaction')`
* (cleared when they finish), queries without a `transaction` option read the key, and a nested
* `sequelize.transaction(callback)` opens its own transaction instead of a savepoint.
*
* @param namespace - CLS namespace; `AsyncLocalStorage` when omitted.
* @returns The `Sequelize` class.
* @throws Error `Must provide CLS namespace` when `namespace` has no `bind` or `run`.
* @see {@link Sequelize.transaction}
*
* @example
* ```ts
* Sequelize.useCLS();
* await sequelize.transaction(async () => {
* // No `{ transaction }` option needed: the queries join the managed transaction.
* const user = await User.create({ name: 'Ada' });
* await Post.create({ title: 'Hello', userId: user.id });
* });
* ```
*/
static useCLS(namespace?: unknown): typeof Sequelize {
transactionScope.enableCls(namespace);
return Sequelize;
}
/**
* Creates an instance from a connection URI.
*
* @param uri - `postgres://user:password@host:port/database`.
* @param options - Options.
*/
constructor(uri: string, options?: SequelizeOptions);
/**
* Creates an instance from connection parameters.
*
* @param database - Database name.
* @param username - User name.
* @param password - Password.
* @param options - Options.
*/
constructor(
database: string,
username?: string | null,
password?: string | null,
options?: SequelizeOptions,
);
/**
* Creates an instance from options only.
*
* @param options - Options including connection settings.
*/
constructor(options?: SequelizeOptions);
// oxlint-disable-next-line no-useless-constructor -- re-declares the typed overloads that mixin construction would erase.
constructor(...args: readonly unknown[]) {
super(...args);
}
}
|