From 20b02f7bc31adde6909af600f7e163521f746929 Mon Sep 17 00:00:00 2001 From: Vadim Kononov Date: Tue, 9 Sep 2025 14:27:04 +0300 Subject: [PATCH] second dialect for tests --- lib/dialects/postgres/index.js | 6 ++++-- lib/model.js | 9 +++++++-- lib/sequelize.js | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/dialects/postgres/index.js b/lib/dialects/postgres/index.js index 562939ad7414..e38d6afa64a2 100644 --- a/lib/dialects/postgres/index.js +++ b/lib/dialects/postgres/index.js @@ -9,10 +9,12 @@ const DataTypes = require('../../data-types').postgres; const { PostgresQueryInterface } = require('./query-interface'); class PostgresDialect extends AbstractDialect { - constructor(sequelize) { + constructor(sequelize, skipConnection = false) { super(); this.sequelize = sequelize; - this.connectionManager = new ConnectionManager(this, sequelize); + if (!skipConnection) { + this.connectionManager = new ConnectionManager(this, sequelize); + } this.queryGenerator = new QueryGenerator({ _dialect: this, sequelize diff --git a/lib/model.js b/lib/model.js index 9960422d2383..7d8b8b7d55c1 100644 --- a/lib/model.js +++ b/lib/model.js @@ -55,6 +55,10 @@ class Model { return this.sequelize.getQueryInterface(); } + static get queryInterface2() { + return this.sequelize.getQueryInterface2(); + } + static get queryGenerator() { return this.queryInterface.queryGenerator; } @@ -1751,9 +1755,10 @@ class Model { await this.runHooks('beforeFindAfterOptions', options); } const selectOptions = { ...options, tableNames: Object.keys(tableNames) }; - const results = await this.queryInterface.select(this, this.getTableName(selectOptions), selectOptions); + const tableName = this.getTableName(selectOptions); + const results = await this.queryInterface.select(this, tableName, selectOptions); if (options.hooks) { - await this.runHooks('afterFind', results, options); + await this.runHooks('afterFind', results, {...options, tableName }); } //rejectOnEmpty mode diff --git a/lib/sequelize.js b/lib/sequelize.js index cbd79d081d47..f284f389ea9a 100644 --- a/lib/sequelize.js +++ b/lib/sequelize.js @@ -322,6 +322,7 @@ class Sequelize { }; let Dialect; + let Dialect2; // Requiring the dialect in a switch-case to keep the // require calls static. (Browserify fix) switch (this.getDialect()) { @@ -339,6 +340,7 @@ class Sequelize { break; case 'sqlite': Dialect = require('./dialects/sqlite'); + Dialect2 = require('./dialects/postgres'); break; default: throw new Error(`The dialect ${this.getDialect()} is not supported. Supported dialects: mssql, mariadb, mysql, postgres, and sqlite.`); @@ -347,6 +349,9 @@ class Sequelize { this.dialect = new Dialect(this); this.dialect.queryGenerator.typeValidation = options.typeValidation; + if (Dialect2) { + this.dialect2 = new Dialect2(this, true); + } if (_.isPlainObject(this.options.operatorsAliases)) { deprecations.noStringOperators(); this.dialect.queryGenerator.setOperatorsAliases(this.options.operatorsAliases); @@ -355,6 +360,9 @@ class Sequelize { } this.queryInterface = this.dialect.queryInterface; + if (this.dialect2) { + this.queryInterface2 = this.dialect2.queryInterface; + } /** * Models are stored here under the name given to `sequelize.define` @@ -402,6 +410,10 @@ class Sequelize { return this.queryInterface; } + getQueryInterface2() { + return this.queryInterface2; + } + /** * Define a new model, representing a table in the database. *