Comparing version 6.5.1 to 6.6.0
@@ -49,3 +49,3 @@ 'use strict'; | ||
Hoek.assert(['contains', 'not', 'or', 'unset'].indexOf(value.type) !== -1, `Unknown criteria value type ${value.type}`); | ||
Hoek.assert(['contains', 'is', 'not', 'or', 'unset'].indexOf(value.type) !== -1, `Unknown criteria value type ${value.type}`); | ||
@@ -82,4 +82,9 @@ if (value.type === 'contains') { | ||
if (typeof orValue === 'function') { | ||
Hoek.assert(orValue.type === 'unset', `Unknown or criteria value type ${orValue.type}`); | ||
ors.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not()); | ||
Hoek.assert(['unset', 'is'].indexOf(orValue.type) !== -1, `Unknown or criteria value type ${orValue.type}`); | ||
if (orValue.type === 'unset') { | ||
ors.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not()); | ||
} | ||
else { | ||
ors.push(internals.toComparator(row, orValue)); | ||
} | ||
} | ||
@@ -101,2 +106,8 @@ else if (typeof orValue === 'object') { | ||
} | ||
else if (value.type === 'is') { | ||
// Is | ||
tests.push(internals.toComparator(row, value)); | ||
} | ||
else { | ||
@@ -177,1 +188,18 @@ | ||
}; | ||
internals.comparators = { | ||
'<': 'lt', | ||
'>': 'gt', | ||
'=': 'eq', | ||
'<=': 'le', | ||
'>=': 'ge', | ||
'!=': 'ne' | ||
}; | ||
internals.toComparator = function (row, value) { | ||
const operator = internals.comparators[value.flags.comparator] || value.flags.comparator; | ||
return row[operator](value.value).default(null); | ||
}; |
@@ -492,2 +492,8 @@ 'use strict'; | ||
static is(comparator, value) { | ||
Hoek.assert(['<', '>', '=', '!=', '<=', '>=', 'lt', 'gt', 'eq', 'ne', 'le', 'ge'].indexOf(comparator) !== -1, `Unknown comparator: ${comparator}`); | ||
return internals.special('is', value, { comparator }); | ||
} | ||
// Criteria or Modifier | ||
@@ -526,2 +532,3 @@ | ||
internals.Db.prototype.override = internals.Db.override; | ||
internals.Db.prototype.is = internals.Db.is; | ||
@@ -528,0 +535,0 @@ |
@@ -95,2 +95,6 @@ 'use strict'; | ||
if (options.filter) { | ||
selection = selection.pluck(options.filter); | ||
} | ||
this._run(selection, 'query', { criteria, options }, callback); | ||
@@ -97,0 +101,0 @@ } |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "6.5.1", | ||
"version": "6.6.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur", |
@@ -104,2 +104,21 @@ 'use strict'; | ||
it('parses or with comparator', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 3 }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
db.test.query({ a: db.or([db.is('>=', 3), db.is('eq', 1)]) }, (err, result) => { | ||
expect(err).to.not.exist(); | ||
expect(result).to.equal([{ id: 3, a: 3 }, { id: 1, a: 1 }]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('parses or unset', (done) => { | ||
@@ -212,2 +231,21 @@ | ||
it('parses is', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 3 }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
db.test.query({ a: db.is('<', 2) }, (err, result) => { | ||
expect(err).to.not.exist(); | ||
expect(result).to.equal([{ id: 1, a: 1 }]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('parses contains', (done) => { | ||
@@ -214,0 +252,0 @@ |
@@ -387,2 +387,21 @@ 'use strict'; | ||
}); | ||
it('filters fields', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1, b: 1 }, { id: 2, a: 2, b: 1 }, { id: 3, a: 3, b: 1 }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
db.test.query({ a: 1 }, { filter: ['b'] }, (err, result) => { | ||
expect(err).to.not.exist(); | ||
expect(result).to.equal([{ b: 1 }]); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -389,0 +408,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201878
4830