不要怂,就是干,撸起袖子干!

Commit b1f106ca by Mick Hansen

refactor(sql/where): move more cases to whereQuery

1 parent b5f7153c
...@@ -1630,6 +1630,8 @@ module.exports = (function() { ...@@ -1630,6 +1630,8 @@ module.exports = (function() {
if (value instanceof Utils.or || value instanceof Utils.and) { if (value instanceof Utils.or || value instanceof Utils.and) {
key = value instanceof Utils.or ? "$or" : "$and"; key = value instanceof Utils.or ? "$or" : "$and";
value = value.args; value = value.args;
} else if (typeof value === "string") {
return value;
} }
} }
...@@ -1766,7 +1768,10 @@ module.exports = (function() { ...@@ -1766,7 +1768,10 @@ module.exports = (function() {
prefix: prepend && tableName prefix: prepend && tableName
}); });
} else if (typeof smth === 'string') { } else if (typeof smth === 'string') {
result = smth; return self.whereItemsQuery(smth, {
model: factory,
prefix: prepend && tableName
});
} else if (Buffer.isBuffer(smth)) { } else if (Buffer.isBuffer(smth)) {
result = this.escape(smth); result = this.escape(smth);
} else if (Array.isArray(smth)) { } else if (Array.isArray(smth)) {
...@@ -1779,7 +1784,10 @@ module.exports = (function() { ...@@ -1779,7 +1784,10 @@ module.exports = (function() {
result = Utils.format(smth, this.dialect); result = Utils.format(smth, this.dialect);
} }
} else if (smth === null) { } else if (smth === null) {
result = '1=1'; return self.whereItemsQuery(smth, {
model: factory,
prefix: prepend && tableName
});
} }
return result ? result : '1=1'; return result ? result : '1=1';
......
...@@ -316,12 +316,12 @@ if (Support.dialectIsMySQL()) { ...@@ -316,12 +316,12 @@ if (Support.dialectIsMySQL()) {
}, { }, {
title: 'no where arguments (string)', title: 'no where arguments (string)',
arguments: ['myTable', {where: ''}], arguments: ['myTable', {where: ''}],
expectation: 'SELECT * FROM `myTable` WHERE 1=1;', expectation: 'SELECT * FROM `myTable`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'no where arguments (null)', title: 'no where arguments (null)',
arguments: ['myTable', {where: null}], arguments: ['myTable', {where: null}],
expectation: 'SELECT * FROM `myTable` WHERE 1=1;', expectation: 'SELECT * FROM `myTable`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'buffer as where argument', title: 'buffer as where argument',
......
...@@ -299,12 +299,12 @@ if (dialect === 'sqlite') { ...@@ -299,12 +299,12 @@ if (dialect === 'sqlite') {
}, { }, {
title: 'no where arguments (string)', title: 'no where arguments (string)',
arguments: ['myTable', {where: ''}], arguments: ['myTable', {where: ''}],
expectation: 'SELECT * FROM `myTable` WHERE 1=1;', expectation: 'SELECT * FROM `myTable`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'no where arguments (null)', title: 'no where arguments (null)',
arguments: ['myTable', {where: null}], arguments: ['myTable', {where: null}],
expectation: 'SELECT * FROM `myTable` WHERE 1=1;', expectation: 'SELECT * FROM `myTable`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'buffer as where argument', title: 'buffer as where argument',
......
...@@ -78,6 +78,10 @@ suite('SQL', function() { ...@@ -78,6 +78,10 @@ suite('SQL', function() {
}); });
}; };
testsql(undefined, 'lol=1', {
default: "lol=1"
});
testsql('deleted', null, { testsql('deleted', null, {
default: "`deleted` IS NULL", default: "`deleted` IS NULL",
postgres: '"deleted" IS NULL', postgres: '"deleted" IS NULL',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!