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

Commit cc80c087 by Mick Hansen

feat(sql/where): add ANY and ANY VALUES support

1 parent de1d3e9d
...@@ -1705,6 +1705,15 @@ module.exports = (function() { ...@@ -1705,6 +1705,15 @@ module.exports = (function() {
value = '('+(value.$in || value.$not || value.$notIn || value).map(function (item) { value = '('+(value.$in || value.$not || value.$notIn || value).map(function (item) {
return self.escape(item); return self.escape(item);
}).join(', ')+')'; }).join(', ')+')';
} else if (value && value.$any) {
comparator = '= ANY';
if (value.$any.$values) {
value = '(VALUES '+value.$any.$values.map(function (value) {
return '('+this.escape(value)+')';
}.bind(this)).join(', ')+')';
} else {
value = '('+this.escape(value.$any, field)+')';
}
} else if (value && (value.$between || value.$notBetween)) { } else if (value && (value.$between || value.$notBetween)) {
comparator = 'BETWEEN'; comparator = 'BETWEEN';
if (value.$notBetween) comparator = 'NOT BETWEEN'; if (value.$notBetween) comparator = 'NOT BETWEEN';
......
...@@ -237,6 +237,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -237,6 +237,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
if (current.dialect.supports['ARRAY']) { if (current.dialect.supports['ARRAY']) {
suite('ARRAY', function () { suite('ARRAY', function () {
suite('$contains', function () {
testsql('muscles', { testsql('muscles', {
$contains: [2, 3] $contains: [2, 3]
}, { }, {
...@@ -271,6 +272,47 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -271,6 +272,47 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
postgres: '"muscles" @> ARRAY[2,5]::INTEGER[]' postgres: '"muscles" @> ARRAY[2,5]::INTEGER[]'
}); });
}); });
suite('$any', function() {
testsql('userId', {
$any: [4, 5, 6]
}, {
postgres: '"userId" = ANY (ARRAY[4,5,6])'
});
testsql('userId', {
$any: [2, 5]
}, {
field: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
}
}, {
postgres: '"userId" = ANY (ARRAY[2,5]::INTEGER[])'
});
suite('$values', function () {
testsql('userId', {
$any: {
$values: [4, 5, 6]
}
}, {
postgres: '"userId" = ANY (VALUES (4), (5), (6))'
});
testsql('userId', {
$any: {
$values: [2, 5]
}
}, {
field: {
type: DataTypes.ARRAY(DataTypes.INTEGER)
}
}, {
postgres: '"userId" = ANY (VALUES (2), (5))'
});
});
});
});
} }
}); });
}); });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!