Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pg v7 regressions #8029

Closed
wants to merge 3 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/dialects/postgres/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ const Promise = require('../../promise');
const sequelizeErrors = require('../../errors.js');
const _ = require('lodash');

function squashResults(results) {
if (!Array.isArray(results)) {
return results;
}

let rowCount = 0;
let rows = [];
let fields = [];

for (const result of results) {
if (!Number.isNaN(result.rowCount)) {
rowCount += result.rowCount;
}

if (result.fields.length > 0 && fields.length === 0) {
fields = result.fields;
}

if (result.rows.length > 0) {
rows = rows.concat(result.rows);
}
}

const last = results[results.length - 1];

return Object.assign({}, last, {
rows,
fields,
rowCount: rowCount === 0 ? NaN : rowCount,
});
}

class Query extends AbstractQuery {
constructor(client, sequelize, options) {
super();
Expand Down Expand Up @@ -95,8 +127,9 @@ class Query extends AbstractQuery {
return queryResult;
})
.then(queryResult => {
const rows = queryResult.rows;
const rowCount = queryResult.rowCount;
const squashed = squashResults(queryResult);
const rows = squashed.rows;
const rowCount = squashed.rowCount;
const isTableNameQuery = sql.indexOf('SELECT table_name FROM information_schema.tables') === 0;
const isRelNameQuery = sql.indexOf('SELECT relname FROM pg_class WHERE oid IN') === 0;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
"lcov-result-merger": "^1.2.0",
"mocha": "^3.0.2",
"mysql2": "^1.2.0",
"pg": "^6.1.0",
"pg": "^7.0.0",
"pg-hstore": "^2.3.2",
"pg-native": "^1.10.0",
"pg-native": "^2.0.0",
"pg-types": "^1.11.0",
"rimraf": "^2.5.4",
"semantic-release": "^6.3.6",
Expand Down