Merge pull request #134 from marvinirwin/fix-bad-where

Fix bad where
This commit is contained in:
Miroslav Bajtoš 2019-09-20 17:29:07 +02:00 committed by GitHub
commit 0f548ed9ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -1182,6 +1182,7 @@ SQLConnector.prototype._buildWhere = function(model, where) {
let params = [];
const sqls = [];
for (let k = 0, s = whereStmts.length; k < s; k++) {
if (!whereStmts[k].sql) continue;
sqls.push(whereStmts[k].sql);
params = params.concat(whereStmts[k].params);
}

View File

@ -247,6 +247,14 @@ describe('sql connector', function() {
});
});
it('builds where and ignores invalid clauses in or', function() {
const where = connector.buildWhere('customer', {
name: 'icecream',
or: [{notAColumnName: ''}, {notAColumnNameEither: ''}],
});
expect(where.sql).to.not.match(/ AND $/);
});
it('builds order by with one field', function() {
const orderBy = connector.buildOrderBy('customer', 'name');
expect(orderBy).to.eql('ORDER BY `NAME`');