Skip to content

Commit

Permalink
Return more information about empty updates (#3597)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Dec 28, 2019
1 parent c277edb commit 9b37c94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/query/compiler.js
Expand Up @@ -18,7 +18,6 @@ const {
omitBy,
reduce,
has,
keys,
} = require('lodash');
const uuid = require('uuid');

Expand Down Expand Up @@ -579,9 +578,7 @@ assign(QueryCompiler.prototype, {
},

distinctOn(value) {
throw new Error(
'.distinctOn() is currently only supported on PostgreSQL'
)
throw new Error('.distinctOn() is currently only supported on PostgreSQL');
},

// On Clause
Expand Down Expand Up @@ -786,7 +783,7 @@ assign(QueryCompiler.prototype, {
_prepUpdate(data = {}) {
const { counter = {} } = this.single;

for (const column of keys(counter)) {
for (const column of Object.keys(counter)) {
//Skip?
if (has(data, column)) {
//Needed?
Expand Down Expand Up @@ -827,6 +824,10 @@ assign(QueryCompiler.prototype, {
'Empty .update() call detected!',
'Update data does not contain any values to update.',
'This will result in a faulty query.',
this.single.table ? `Table: ${this.single.table}.` : '',
this.single.update
? `Columns: ${Object.keys(this.single.update)}.`
: '',
].join(' ')
);
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/query/builder.js
@@ -1,7 +1,7 @@
/*global expect*/
/*eslint no-var:0, indent:0, max-len:0 */
'use strict';

const { expect } = require('chai');
const MySQL_Client = require('../../../lib/dialects/mysql');
const PG_Client = require('../../../lib/dialects/postgres');
const Redshift_Client = require('../../../lib/dialects/redshift');
Expand Down Expand Up @@ -9546,12 +9546,12 @@ describe('QueryBuilder', () => {
try {
qb()
.table('sometable')
.update({ column: undefined })
.update({ foobar: undefined })
.toString();
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'Empty .update() call detected! Update data does not contain any values to update. This will result in a faulty query.'
'Empty .update() call detected! Update data does not contain any values to update. This will result in a faulty query. Table: sometable. Columns: foobar.'
);
}
});
Expand Down

0 comments on commit 9b37c94

Please sign in to comment.