Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/dialects/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class Model {
return this.sequelize.getQueryInterface();
}

static get queryInterface2() {
return this.sequelize.getQueryInterface2();
}

static get queryGenerator() {
return this.queryInterface.queryGenerator;
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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.`);
Expand All @@ -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);
Expand All @@ -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`
Expand Down Expand Up @@ -402,6 +410,10 @@ class Sequelize {
return this.queryInterface;
}

getQueryInterface2() {
return this.queryInterface2;
}

/**
* Define a new model, representing a table in the database.
*
Expand Down
Loading