sequelize.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __defProps = Object.defineProperties;
  4. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  5. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  6. var __hasOwnProp = Object.prototype.hasOwnProperty;
  7. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  8. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  9. var __spreadValues = (a, b) => {
  10. for (var prop in b || (b = {}))
  11. if (__hasOwnProp.call(b, prop))
  12. __defNormalProp(a, prop, b[prop]);
  13. if (__getOwnPropSymbols)
  14. for (var prop of __getOwnPropSymbols(b)) {
  15. if (__propIsEnum.call(b, prop))
  16. __defNormalProp(a, prop, b[prop]);
  17. }
  18. return a;
  19. };
  20. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  21. const url = require("url");
  22. const path = require("path");
  23. const pgConnectionString = require("pg-connection-string");
  24. const retry = require("retry-as-promised").default;
  25. const _ = require("lodash");
  26. const Utils = require("./utils");
  27. const Model = require("./model");
  28. const DataTypes = require("./data-types");
  29. const Deferrable = require("./deferrable");
  30. const ModelManager = require("./model-manager");
  31. const Transaction = require("./transaction");
  32. const QueryTypes = require("./query-types");
  33. const TableHints = require("./table-hints");
  34. const IndexHints = require("./index-hints");
  35. const sequelizeErrors = require("./errors");
  36. const Hooks = require("./hooks");
  37. const Association = require("./associations/index");
  38. const Validator = require("./utils/validator-extras").validator;
  39. const Op = require("./operators");
  40. const deprecations = require("./utils/deprecations");
  41. const { QueryInterface } = require("./dialects/abstract/query-interface");
  42. const { BelongsTo } = require("./associations/belongs-to");
  43. const HasOne = require("./associations/has-one");
  44. const { BelongsToMany } = require("./associations/belongs-to-many");
  45. const { HasMany } = require("./associations/has-many");
  46. const { withSqliteForeignKeysOff } = require("./dialects/sqlite/sqlite-utils");
  47. const { injectReplacements } = require("./utils/sql");
  48. class Sequelize {
  49. constructor(database, username, password, options) {
  50. let config;
  51. if (arguments.length === 1 && typeof database === "object") {
  52. options = database;
  53. config = _.pick(options, "host", "port", "database", "username", "password");
  54. } else if (arguments.length === 1 && typeof database === "string" || arguments.length === 2 && typeof username === "object") {
  55. config = {};
  56. options = username || {};
  57. const urlParts = url.parse(arguments[0], true);
  58. options.dialect = urlParts.protocol.replace(/:$/, "");
  59. options.host = urlParts.hostname;
  60. if (options.dialect === "sqlite" && urlParts.pathname && !urlParts.pathname.startsWith("/:memory")) {
  61. const storagePath = path.join(options.host, urlParts.pathname);
  62. options.storage = path.resolve(options.storage || storagePath);
  63. }
  64. if (urlParts.pathname) {
  65. config.database = urlParts.pathname.replace(/^\//, "");
  66. }
  67. if (urlParts.port) {
  68. options.port = urlParts.port;
  69. }
  70. if (urlParts.auth) {
  71. const authParts = urlParts.auth.split(":");
  72. config.username = authParts[0];
  73. if (authParts.length > 1)
  74. config.password = authParts.slice(1).join(":");
  75. }
  76. if (urlParts.query) {
  77. if (urlParts.query.host) {
  78. options.host = urlParts.query.host;
  79. }
  80. if (options.dialectOptions) {
  81. Object.assign(options.dialectOptions, urlParts.query);
  82. } else {
  83. options.dialectOptions = urlParts.query;
  84. if (urlParts.query.options) {
  85. try {
  86. const o = JSON.parse(urlParts.query.options);
  87. options.dialectOptions.options = o;
  88. } catch (e) {
  89. }
  90. }
  91. }
  92. }
  93. if (["postgres", "postgresql"].includes(options.dialect)) {
  94. Object.assign(options.dialectOptions, pgConnectionString.parse(arguments[0]));
  95. }
  96. } else {
  97. options = options || {};
  98. config = { database, username, password };
  99. }
  100. Sequelize.runHooks("beforeInit", config, options);
  101. this.options = __spreadValues({
  102. dialect: null,
  103. dialectModule: null,
  104. dialectModulePath: null,
  105. host: "localhost",
  106. protocol: "tcp",
  107. define: {},
  108. query: {},
  109. sync: {},
  110. timezone: "+00:00",
  111. standardConformingStrings: true,
  112. logging: console.log,
  113. omitNull: false,
  114. native: false,
  115. replication: false,
  116. ssl: void 0,
  117. pool: {},
  118. quoteIdentifiers: true,
  119. hooks: {},
  120. retry: {
  121. max: 5,
  122. match: [
  123. "SQLITE_BUSY: database is locked"
  124. ]
  125. },
  126. transactionType: Transaction.TYPES.DEFERRED,
  127. isolationLevel: null,
  128. databaseVersion: 0,
  129. typeValidation: false,
  130. benchmark: false,
  131. minifyAliases: false,
  132. logQueryParameters: false,
  133. attributeBehavior: "throw"
  134. }, options);
  135. if (!this.options.dialect) {
  136. throw new Error("Dialect needs to be explicitly supplied as of v4.0.0");
  137. }
  138. if (this.options.dialect === "postgresql") {
  139. this.options.dialect = "postgres";
  140. }
  141. if (this.options.dialect === "sqlite" && this.options.timezone !== "+00:00") {
  142. throw new Error("Setting a custom timezone is not supported by SQLite, dates are always returned as UTC. Please remove the custom timezone parameter.");
  143. }
  144. if (this.options.logging === true) {
  145. deprecations.noTrueLogging();
  146. this.options.logging = console.log;
  147. }
  148. this._setupHooks(options.hooks);
  149. this.config = {
  150. database: config.database || this.options.database,
  151. username: config.username || this.options.username,
  152. password: config.password || this.options.password || null,
  153. host: config.host || this.options.host,
  154. port: config.port || this.options.port,
  155. pool: this.options.pool,
  156. protocol: this.options.protocol,
  157. native: this.options.native,
  158. ssl: this.options.ssl,
  159. replication: this.options.replication,
  160. dialectModule: this.options.dialectModule,
  161. dialectModulePath: this.options.dialectModulePath,
  162. keepDefaultTimezone: this.options.keepDefaultTimezone,
  163. dialectOptions: this.options.dialectOptions
  164. };
  165. let Dialect;
  166. switch (this.getDialect()) {
  167. case "mariadb":
  168. Dialect = require("./dialects/mariadb");
  169. break;
  170. case "mssql":
  171. Dialect = require("./dialects/mssql");
  172. break;
  173. case "mysql":
  174. Dialect = require("./dialects/mysql");
  175. break;
  176. case "oracle":
  177. Dialect = require("./dialects/oracle");
  178. break;
  179. case "postgres":
  180. Dialect = require("./dialects/postgres");
  181. break;
  182. case "sqlite":
  183. Dialect = require("./dialects/sqlite");
  184. break;
  185. case "db2":
  186. Dialect = require("./dialects/db2");
  187. break;
  188. case "snowflake":
  189. Dialect = require("./dialects/snowflake");
  190. break;
  191. default:
  192. throw new Error(`The dialect ${this.getDialect()} is not supported. Supported dialects: mssql, mariadb, mysql, oracle, postgres, db2 and sqlite.`);
  193. }
  194. this.dialect = new Dialect(this);
  195. this.dialect.queryGenerator.typeValidation = options.typeValidation;
  196. if (_.isPlainObject(this.options.operatorsAliases)) {
  197. deprecations.noStringOperators();
  198. this.dialect.queryGenerator.setOperatorsAliases(this.options.operatorsAliases);
  199. } else if (typeof this.options.operatorsAliases === "boolean") {
  200. deprecations.noBoolOperatorAliases();
  201. }
  202. this.queryInterface = this.dialect.queryInterface;
  203. this.models = {};
  204. this.modelManager = new ModelManager(this);
  205. this.connectionManager = this.dialect.connectionManager;
  206. Sequelize.runHooks("afterInit", this);
  207. }
  208. refreshTypes() {
  209. this.connectionManager.refreshTypeParser(DataTypes);
  210. }
  211. getDialect() {
  212. return this.options.dialect;
  213. }
  214. getDatabaseName() {
  215. return this.config.database;
  216. }
  217. getQueryInterface() {
  218. return this.queryInterface;
  219. }
  220. define(modelName, attributes, options = {}) {
  221. options.modelName = modelName;
  222. options.sequelize = this;
  223. const model = class extends Model {
  224. };
  225. model.init(attributes, options);
  226. return model;
  227. }
  228. model(modelName) {
  229. if (!this.isDefined(modelName)) {
  230. throw new Error(`${modelName} has not been defined`);
  231. }
  232. return this.modelManager.getModel(modelName);
  233. }
  234. isDefined(modelName) {
  235. return !!this.modelManager.models.find((model) => model.name === modelName);
  236. }
  237. async query(sql, options) {
  238. options = __spreadValues(__spreadValues({}, this.options.query), options);
  239. if (options.instance && !options.model) {
  240. options.model = options.instance.constructor;
  241. }
  242. if (!options.instance && !options.model) {
  243. options.raw = true;
  244. }
  245. if (options.mapToModel) {
  246. options.fieldMap = _.get(options, "model.fieldAttributeMap", {});
  247. }
  248. options = _.defaults(options, {
  249. logging: Object.prototype.hasOwnProperty.call(this.options, "logging") ? this.options.logging : console.log,
  250. searchPath: Object.prototype.hasOwnProperty.call(this.options, "searchPath") ? this.options.searchPath : "DEFAULT"
  251. });
  252. if (!options.type) {
  253. if (options.model || options.nest || options.plain) {
  254. options.type = QueryTypes.SELECT;
  255. } else {
  256. options.type = QueryTypes.RAW;
  257. }
  258. }
  259. if (!this.dialect.supports.searchPath || !this.options.dialectOptions || !this.options.dialectOptions.prependSearchPath || options.supportsSearchPath === false) {
  260. delete options.searchPath;
  261. } else if (!options.searchPath) {
  262. options.searchPath = "DEFAULT";
  263. }
  264. if (typeof sql === "object") {
  265. if (sql.values !== void 0) {
  266. if (options.replacements !== void 0) {
  267. throw new Error("Both `sql.values` and `options.replacements` cannot be set at the same time");
  268. }
  269. options.replacements = sql.values;
  270. }
  271. if (sql.bind !== void 0) {
  272. if (options.bind !== void 0) {
  273. throw new Error("Both `sql.bind` and `options.bind` cannot be set at the same time");
  274. }
  275. options.bind = sql.bind;
  276. }
  277. if (sql.query !== void 0) {
  278. sql = sql.query;
  279. }
  280. }
  281. sql = sql.trim();
  282. if (options.replacements && options.bind) {
  283. throw new Error("Both `replacements` and `bind` cannot be set at the same time");
  284. }
  285. if (options.replacements) {
  286. sql = injectReplacements(sql, this.dialect, options.replacements);
  287. }
  288. let bindParameters;
  289. if (options.bind) {
  290. [sql, bindParameters] = this.dialect.Query.formatBindParameters(sql, options.bind, this.options.dialect);
  291. }
  292. const checkTransaction = () => {
  293. if (options.transaction && options.transaction.finished && !options.completesTransaction) {
  294. const error = new Error(`${options.transaction.finished} has been called on this transaction(${options.transaction.id}), you can no longer use it. (The rejected query is attached as the 'sql' property of this error)`);
  295. error.sql = sql;
  296. throw error;
  297. }
  298. };
  299. const retryOptions = __spreadValues(__spreadValues({}, this.options.retry), options.retry);
  300. return retry(async () => {
  301. if (options.transaction === void 0 && Sequelize._cls) {
  302. options.transaction = Sequelize._cls.get("transaction");
  303. }
  304. checkTransaction();
  305. const connection = await (options.transaction ? options.transaction.connection : this.connectionManager.getConnection(options));
  306. if (this.options.dialect === "db2" && options.alter) {
  307. if (options.alter.drop === false) {
  308. connection.dropTable = false;
  309. }
  310. }
  311. const query = new this.dialect.Query(connection, this, options);
  312. try {
  313. await this.runHooks("beforeQuery", options, query);
  314. checkTransaction();
  315. return await query.run(sql, bindParameters);
  316. } finally {
  317. await this.runHooks("afterQuery", options, query);
  318. if (!options.transaction) {
  319. this.connectionManager.releaseConnection(connection);
  320. }
  321. }
  322. }, retryOptions);
  323. }
  324. async set(variables, options) {
  325. options = __spreadValues(__spreadValues({}, this.options.set), typeof options === "object" && options);
  326. if (!["mysql", "mariadb"].includes(this.options.dialect)) {
  327. throw new Error("sequelize.set is only supported for mysql or mariadb");
  328. }
  329. if (!options.transaction || !(options.transaction instanceof Transaction)) {
  330. throw new TypeError("options.transaction is required");
  331. }
  332. options.raw = true;
  333. options.plain = true;
  334. options.type = "SET";
  335. const query = `SET ${_.map(variables, (v, k) => `@${k} := ${typeof v === "string" ? `"${v}"` : v}`).join(", ")}`;
  336. return await this.query(query, options);
  337. }
  338. escape(value) {
  339. return this.dialect.queryGenerator.escape(value);
  340. }
  341. async createSchema(schema, options) {
  342. return await this.getQueryInterface().createSchema(schema, options);
  343. }
  344. async showAllSchemas(options) {
  345. return await this.getQueryInterface().showAllSchemas(options);
  346. }
  347. async dropSchema(schema, options) {
  348. return await this.getQueryInterface().dropSchema(schema, options);
  349. }
  350. async dropAllSchemas(options) {
  351. return await this.getQueryInterface().dropAllSchemas(options);
  352. }
  353. async sync(options) {
  354. options = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.options), this.options.sync), options), {
  355. hooks: options ? options.hooks !== false : true
  356. });
  357. if (options.match) {
  358. if (!options.match.test(this.config.database)) {
  359. throw new Error(`Database "${this.config.database}" does not match sync match parameter "${options.match}"`);
  360. }
  361. }
  362. if (options.hooks) {
  363. await this.runHooks("beforeBulkSync", options);
  364. }
  365. if (options.force) {
  366. await this.drop(options);
  367. }
  368. if (this.modelManager.models.length === 0) {
  369. await this.authenticate(options);
  370. } else {
  371. const models = this.modelManager.getModelsTopoSortedByForeignKey();
  372. if (models == null) {
  373. return this._syncModelsWithCyclicReferences(options);
  374. }
  375. models.reverse();
  376. for (const model of models) {
  377. await model.sync(options);
  378. }
  379. }
  380. if (options.hooks) {
  381. await this.runHooks("afterBulkSync", options);
  382. }
  383. return this;
  384. }
  385. async _syncModelsWithCyclicReferences(options) {
  386. if (this.dialect.name === "sqlite") {
  387. await withSqliteForeignKeysOff(this, options, async () => {
  388. for (const model of this.modelManager.models) {
  389. await model.sync(options);
  390. }
  391. });
  392. return;
  393. }
  394. for (const model of this.modelManager.models) {
  395. await model.sync(__spreadProps(__spreadValues({}, options), { withoutForeignKeyConstraints: true }));
  396. }
  397. for (const model of this.modelManager.models) {
  398. await model.sync(__spreadProps(__spreadValues({}, options), { force: false, alter: true }));
  399. }
  400. }
  401. async truncate(options) {
  402. const sortedModels = this.modelManager.getModelsTopoSortedByForeignKey();
  403. const models = sortedModels || this.modelManager.models;
  404. const hasCyclicDependencies = sortedModels == null;
  405. if (hasCyclicDependencies && (!options || !options.cascade)) {
  406. throw new Error('Sequelize#truncate: Some of your models have cyclic references (foreign keys). You need to use the "cascade" option to be able to delete rows from models that have cyclic references.');
  407. }
  408. if (hasCyclicDependencies && this.dialect.name === "sqlite") {
  409. return withSqliteForeignKeysOff(this, options, async () => {
  410. await Promise.all(models.map((model) => model.truncate(options)));
  411. });
  412. }
  413. if (options && options.cascade) {
  414. for (const model of models)
  415. await model.truncate(options);
  416. } else {
  417. await Promise.all(models.map((model) => model.truncate(options)));
  418. }
  419. }
  420. async drop(options) {
  421. if (options && options.cascade) {
  422. for (const model of this.modelManager.models) {
  423. await model.drop(options);
  424. }
  425. }
  426. const sortedModels = this.modelManager.getModelsTopoSortedByForeignKey();
  427. if (sortedModels) {
  428. for (const model of sortedModels) {
  429. await model.drop(options);
  430. }
  431. }
  432. if (this.dialect.name === "sqlite") {
  433. await withSqliteForeignKeysOff(this, options, async () => {
  434. for (const model of this.modelManager.models) {
  435. await model.drop(options);
  436. }
  437. });
  438. return;
  439. }
  440. for (const model of this.modelManager.models) {
  441. const tableName = model.getTableName();
  442. const foreignKeys = await this.queryInterface.getForeignKeyReferencesForTable(tableName, options);
  443. await Promise.all(foreignKeys.map((foreignKey) => {
  444. return this.queryInterface.removeConstraint(tableName, foreignKey.constraintName, options);
  445. }));
  446. }
  447. for (const model of this.modelManager.models) {
  448. await model.drop(options);
  449. }
  450. }
  451. async authenticate(options) {
  452. options = __spreadValues({
  453. raw: true,
  454. plain: true,
  455. type: QueryTypes.SELECT
  456. }, options);
  457. await this.query(this.dialect.queryGenerator.authTestQuery(), options);
  458. return;
  459. }
  460. async databaseVersion(options) {
  461. return await this.getQueryInterface().databaseVersion(options);
  462. }
  463. random() {
  464. if (["postgres", "sqlite", "snowflake"].includes(this.getDialect())) {
  465. return this.fn("RANDOM");
  466. }
  467. return this.fn("RAND");
  468. }
  469. static fn(fn, ...args) {
  470. return new Utils.Fn(fn, args);
  471. }
  472. static col(col) {
  473. return new Utils.Col(col);
  474. }
  475. static cast(val, type) {
  476. return new Utils.Cast(val, type);
  477. }
  478. static literal(val) {
  479. return new Utils.Literal(val);
  480. }
  481. static and(...args) {
  482. return { [Op.and]: args };
  483. }
  484. static or(...args) {
  485. return { [Op.or]: args };
  486. }
  487. static json(conditionsOrPath, value) {
  488. return new Utils.Json(conditionsOrPath, value);
  489. }
  490. static where(attr, comparator, logic) {
  491. return new Utils.Where(attr, comparator, logic);
  492. }
  493. async transaction(options, autoCallback) {
  494. if (typeof options === "function") {
  495. autoCallback = options;
  496. options = void 0;
  497. }
  498. const transaction = new Transaction(this, options);
  499. if (!autoCallback) {
  500. await transaction.prepareEnvironment(false);
  501. return transaction;
  502. }
  503. return Sequelize._clsRun(async () => {
  504. await transaction.prepareEnvironment(true);
  505. let result;
  506. try {
  507. result = await autoCallback(transaction);
  508. } catch (err) {
  509. try {
  510. await transaction.rollback();
  511. } catch (ignore) {
  512. }
  513. throw err;
  514. }
  515. await transaction.commit();
  516. return result;
  517. });
  518. }
  519. static useCLS(ns) {
  520. if (!ns || typeof ns !== "object" || typeof ns.bind !== "function" || typeof ns.run !== "function")
  521. throw new Error("Must provide CLS namespace");
  522. Sequelize._cls = ns;
  523. return this;
  524. }
  525. static _clsRun(fn) {
  526. const ns = Sequelize._cls;
  527. if (!ns)
  528. return fn();
  529. let res;
  530. ns.run((context) => res = fn(context));
  531. return res;
  532. }
  533. log(...args) {
  534. let options;
  535. const last = _.last(args);
  536. if (last && _.isPlainObject(last) && Object.prototype.hasOwnProperty.call(last, "logging")) {
  537. options = last;
  538. if (options.logging === console.log) {
  539. args.splice(args.length - 1, 1);
  540. }
  541. } else {
  542. options = this.options;
  543. }
  544. if (options.logging) {
  545. if (options.logging === true) {
  546. deprecations.noTrueLogging();
  547. options.logging = console.log;
  548. }
  549. if ((this.options.benchmark || options.benchmark) && options.logging === console.log) {
  550. args = [`${args[0]} Elapsed time: ${args[1]}ms`];
  551. }
  552. options.logging(...args);
  553. }
  554. }
  555. close() {
  556. return this.connectionManager.close();
  557. }
  558. normalizeDataType(Type) {
  559. let type = typeof Type === "function" ? new Type() : Type;
  560. const dialectTypes = this.dialect.DataTypes || {};
  561. if (dialectTypes[type.key]) {
  562. type = dialectTypes[type.key].extend(type);
  563. }
  564. if (type instanceof DataTypes.ARRAY) {
  565. if (!type.type) {
  566. throw new Error("ARRAY is missing type definition for its values.");
  567. }
  568. if (dialectTypes[type.type.key]) {
  569. type.type = dialectTypes[type.type.key].extend(type.type);
  570. }
  571. }
  572. return type;
  573. }
  574. normalizeAttribute(attribute) {
  575. if (!_.isPlainObject(attribute)) {
  576. attribute = { type: attribute };
  577. }
  578. if (!attribute.type)
  579. return attribute;
  580. attribute.type = this.normalizeDataType(attribute.type);
  581. if (Object.prototype.hasOwnProperty.call(attribute, "defaultValue")) {
  582. if (typeof attribute.defaultValue === "function" && [DataTypes.NOW, DataTypes.UUIDV1, DataTypes.UUIDV4].includes(attribute.defaultValue)) {
  583. attribute.defaultValue = new attribute.defaultValue();
  584. }
  585. }
  586. if (attribute.type instanceof DataTypes.ENUM) {
  587. if (attribute.values) {
  588. attribute.type.values = attribute.type.options.values = attribute.values;
  589. } else {
  590. attribute.values = attribute.type.values;
  591. }
  592. if (!attribute.values.length) {
  593. throw new Error("Values for ENUM have not been defined.");
  594. }
  595. }
  596. return attribute;
  597. }
  598. }
  599. Sequelize.prototype.fn = Sequelize.fn;
  600. Sequelize.prototype.col = Sequelize.col;
  601. Sequelize.prototype.cast = Sequelize.cast;
  602. Sequelize.prototype.literal = Sequelize.literal;
  603. Sequelize.prototype.and = Sequelize.and;
  604. Sequelize.prototype.or = Sequelize.or;
  605. Sequelize.prototype.json = Sequelize.json;
  606. Sequelize.prototype.where = Sequelize.where;
  607. Sequelize.prototype.validate = Sequelize.prototype.authenticate;
  608. Object.defineProperty(Sequelize, "version", {
  609. enumerable: true,
  610. get() {
  611. return require("../package.json").version;
  612. }
  613. });
  614. Sequelize.options = { hooks: {} };
  615. Sequelize.Utils = Utils;
  616. Sequelize.Op = Op;
  617. Sequelize.TableHints = TableHints;
  618. Sequelize.IndexHints = IndexHints;
  619. Sequelize.Transaction = Transaction;
  620. Sequelize.prototype.Sequelize = Sequelize;
  621. Sequelize.prototype.QueryTypes = Sequelize.QueryTypes = QueryTypes;
  622. Sequelize.prototype.Validator = Sequelize.Validator = Validator;
  623. Sequelize.Model = Model;
  624. Sequelize.QueryInterface = QueryInterface;
  625. Sequelize.BelongsTo = BelongsTo;
  626. Sequelize.HasOne = HasOne;
  627. Sequelize.HasMany = HasMany;
  628. Sequelize.BelongsToMany = BelongsToMany;
  629. Sequelize.DataTypes = DataTypes;
  630. for (const dataType in DataTypes) {
  631. Sequelize[dataType] = DataTypes[dataType];
  632. }
  633. Sequelize.Deferrable = Deferrable;
  634. Sequelize.prototype.Association = Sequelize.Association = Association;
  635. Sequelize.useInflection = Utils.useInflection;
  636. Hooks.applyTo(Sequelize);
  637. Hooks.applyTo(Sequelize.prototype);
  638. Sequelize.Error = sequelizeErrors.BaseError;
  639. for (const error of Object.keys(sequelizeErrors)) {
  640. Sequelize[error] = sequelizeErrors[error];
  641. }
  642. module.exports = Sequelize;
  643. module.exports.Sequelize = Sequelize;
  644. module.exports.default = Sequelize;
  645. //# sourceMappingURL=sequelize.js.map