Comparing version 5.0.0 to 5.1.0
@@ -57,5 +57,5 @@ 'use strict'; | ||
const value = internals.reach(item, rule.path); | ||
if (value !== undefined) { | ||
fields.push({ rule, value, id: updateId !== null ? updateId : item.id }); | ||
const values = internals.reach(item, rule.path); | ||
if (values !== undefined) { | ||
fields.push({ rule, values, id: updateId !== null ? updateId : item.id }); | ||
@@ -81,5 +81,12 @@ if (updateId) { | ||
const reservation = { id: field.value, created: Date.now() }; | ||
reservation[field.rule.key] = field.id; | ||
field.rule.table.insert(reservation, next); | ||
const now = Date.now(); | ||
const reservations = []; | ||
field.values.forEach((value) => { | ||
const rsv = { id: value, created: now }; | ||
rsv[field.rule.key] = field.id; | ||
reservations.push(rsv); | ||
}); | ||
field.rule.table.insert(reservations, next); | ||
}; | ||
@@ -137,7 +144,17 @@ | ||
if (typeof ref === 'object') { | ||
// Normalize value | ||
if (ref === undefined) { | ||
return undefined; | ||
} | ||
return ref; | ||
if (Array.isArray(ref)) { | ||
return ref; | ||
} | ||
if (typeof ref === 'object') { | ||
return Object.keys(ref); | ||
} | ||
return [ref]; | ||
}; | ||
@@ -144,0 +161,0 @@ |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur", |
# penseur | ||
Lightweight RethinkDB wrapper | ||
Application-friendly RethinkDB client | ||
[![Build Status](https://secure.travis-ci.org/hueniverse/penseur.png)](http://travis-ci.org/hueniverse/penseur) | ||
@@ -140,12 +140,11 @@ 'use strict'; | ||
it('cusomizes unique table name', (done) => { | ||
it('forbids violating a unique value (keys)', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
const settings = { | ||
unique_a: true, // Test cleanup | ||
penseur_unique_test_a: true, // Test cleanup | ||
test: { | ||
id: 'uuid', | ||
unique: { | ||
path: 'a', | ||
table: 'unique_a' | ||
path: 'a' | ||
} | ||
@@ -158,12 +157,17 @@ } | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }], (err, keys) => { | ||
db.test.insert({ a: { b: 1 } }, (err, key1) => { | ||
expect(err).to.not.exist(); | ||
expect(keys.length).to.equal(2); | ||
db.test.insert({ a: { c: 2, d: 4 } }, (err, key2) => { | ||
db.unique_a.get([1, 2], (err, items) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert({ a: { b: 3 } }, (err, key3) => { | ||
expect(err).to.not.exist(); | ||
expect(items.length).to.equal(2); | ||
done(); | ||
expect(err).to.exist(); | ||
db.test.insert({ a: { d: 5 } }, (err, key4) => { | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -174,3 +178,3 @@ }); | ||
it('ignores non unique keys', (done) => { | ||
it('forbids violating a unique value (array)', (done) => { | ||
@@ -191,7 +195,50 @@ const db = new Penseur.Db('penseurtest'); | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ b: 1 }, { b: 2 }], (err, keys) => { | ||
db.test.insert({ a: ['b'] }, (err, key1) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert({ a: ['c', 'a'] }, (err, key2) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert({ a: ['b'] }, (err, key3) => { | ||
expect(err).to.exist(); | ||
db.test.insert({ a: ['a'] }, (err, key4) => { | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('cusomizes unique table name', (done) => { | ||
const db = new Penseur.Db('penseurtest'); | ||
const settings = { | ||
unique_a: true, // Test cleanup | ||
test: { | ||
id: 'uuid', | ||
unique: { | ||
path: 'a', | ||
table: 'unique_a' | ||
} | ||
} | ||
}; | ||
db.establish(settings, (err) => { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
expect(keys.length).to.equal(2); | ||
done(); | ||
db.unique_a.get([1, 2], (err, items) => { | ||
expect(err).to.not.exist(); | ||
expect(items.length).to.equal(2); | ||
done(); | ||
}); | ||
}); | ||
@@ -201,3 +248,3 @@ }); | ||
it('ignore non-plain values', (done) => { | ||
it('ignores non unique keys', (done) => { | ||
@@ -218,5 +265,6 @@ const db = new Penseur.Db('penseurtest'); | ||
expect(err).to.not.exist(); | ||
db.test.insert({ a: { b: 1 } }, (err, key) => { | ||
db.test.insert([{ b: 1 }, { b: 2 }], (err, keys) => { | ||
expect(err).to.not.exist(); | ||
expect(keys.length).to.equal(2); | ||
done(); | ||
@@ -223,0 +271,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
154361
3684
7