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

Commit d0c3a16f by Mick Hansen

feat(where): explicit casting with attribute::integer for json nested querying

1 parent 05059632
......@@ -1759,7 +1759,17 @@ module.exports = (function() {
traverse = function (prop, item, path) {
var $where = {}
, $key
, $baseKey = self.quoteIdentifier(key)+'#>>\'{'+path.join(', ')+'}\'';
, $cast
, $baseKey
, $tmp;
if (path[path.length - 1].indexOf('::') > -1) {
$tmp = path[path.length - 1].split('::');
$cast = $tmp[1];
path[path.length - 1] = $tmp[0];
}
$baseKey = self.quoteIdentifier(key)+'#>>\'{'+path.join(', ')+'}\'';
if (options.prefix) {
if (options.prefix instanceof Utils.literal) {
......@@ -1777,12 +1787,18 @@ module.exports = (function() {
$where[$prop] = $item;
$key = $baseKey;
if (typeof $item === 'number') {
$key += '::double precision';
if (!$cast) {
if (typeof $item === 'number') {
$cast = 'double precision';
}
if ($item instanceof Date) {
$cast = 'timestamptz';
}
}
if ($item instanceof Date) {
$key += '::timestamptz';
if ($cast) {
$key += '::'+$cast;
}
$items.push(self.whereItemQuery(new Utils.literal($key), $where/*, _.pick(options, 'prefix')*/));
......
......@@ -550,6 +550,20 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql('data', {
nested: {
"attribute::integer": {
$gt: 2
}
}
}, {
field: {
type: new DataTypes.JSONB()
}
}, {
default: "([data]#>>'{nested, attribute}')::integer > 2"
});
testsql('data', {
nested: {
attribute: {
$gt: new Date()
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!