json-sql
Advanced tools
Comparing version 0.4.13 to 0.5.0
@@ -12,5 +12,9 @@ 'use strict'; | ||
if (_.isArray(value)) { | ||
result = 'array[' + _(value).map(function(item) { | ||
return dialect.builder._pushValue(item); | ||
}).join(', ') + ']'; | ||
if (value.length) { | ||
result = 'array[' + _(value).map(function(item) { | ||
return dialect.builder._pushValue(item); | ||
}).join(', ') + ']'; | ||
} else { | ||
result = dialect.builder._pushValue('{}'); | ||
} | ||
} else if (_.isObject(value)) { | ||
@@ -17,0 +21,0 @@ result = dialect.builder._pushValue(JSON.stringify(value)); |
@@ -58,2 +58,23 @@ 'use strict'; | ||
}); | ||
dialect.operators.comparison.add('$arrayContains', { | ||
defaultFetchingOperator: '$array', | ||
fn: function(field, value) { | ||
return buildComparisonCondition(field, '@>', value); | ||
} | ||
}); | ||
dialect.operators.comparison.add('$arrayIn', { | ||
defaultFetchingOperator: '$array', | ||
fn: function(field, value) { | ||
return buildComparisonCondition(field, '<@', value); | ||
} | ||
}); | ||
dialect.operators.comparison.add('$arrayOverlap', { | ||
defaultFetchingOperator: '$array', | ||
fn: function(field, value) { | ||
return buildComparisonCondition(field, '&&', value); | ||
} | ||
}); | ||
}; |
'use strict'; | ||
var _ = require('underscore'); | ||
module.exports = function(dialect) { | ||
@@ -10,2 +12,11 @@ dialect.operators.fetching.add('$json', { | ||
}); | ||
dialect.operators.fetching.add('$array', { | ||
fn: function(value) { | ||
if (!_.isArray(value)) { | ||
value = [value]; | ||
} | ||
return dialect.buildBlock('term', {term: value, type: 'value'}); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "json-sql", | ||
"description": "node.js json to sql queries mapper", | ||
"version": "0.4.13", | ||
"version": "0.5.0", | ||
"author": "Artem Zhukov <artzhuchka@gmail.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
1621
59995
29