Comparing version 1.4.0 to 1.4.1
@@ -67,3 +67,28 @@ // Load Modules | ||
return callback(null, result.generated_keys ? (items instanceof Array ? result.generated_keys : result.generated_keys[0]) : null); | ||
// Single item | ||
if (!Array.isArray(items)) { | ||
return callback(null, items.id !== undefined ? items.id : result.generated_keys[0]); | ||
} | ||
// Items array | ||
var generated = result.generated_keys || []; | ||
if (generated.length === items.length) { | ||
return callback(null, result.generated_keys); | ||
} | ||
// Mixed array | ||
var ids = []; | ||
for (var g = 0, i = 0, il = items.length; i < il; ++i) { | ||
if (items[i].id !== undefined) { | ||
ids.push(items[i].id); | ||
} | ||
else { | ||
ids.push(result.generated_keys[g++]); | ||
} | ||
} | ||
return callback(null, ids); | ||
}); | ||
@@ -70,0 +95,0 @@ }; |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur", |
@@ -267,2 +267,17 @@ // Load modules | ||
it('returns the generate key (existing)', function (done) { | ||
var db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], function (err) { | ||
expect(err).to.not.exist(); | ||
db.test.insert({ id: 11, a: 1 }, function (err, keys) { | ||
expect(err).to.not.exist(); | ||
expect(keys).to.equal(11); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('returns the generate keys', function (done) { | ||
@@ -282,2 +297,53 @@ | ||
}); | ||
it('returns the generate keys when keys are present', function (done) { | ||
var db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], function (err) { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ id: 1, a: 1 }, { a: 2 }], function (err, keys) { | ||
expect(err).to.not.exist(); | ||
expect(keys).to.have.length(2); | ||
expect(keys[0]).to.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('returns the generate keys when keys are present (last)', function (done) { | ||
var db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], function (err) { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ a: 1 }, { id: 1, a: 2 }], function (err, keys) { | ||
expect(err).to.not.exist(); | ||
expect(keys).to.have.length(2); | ||
expect(keys[1]).to.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('returns the generate keys when keys are present (mixed)', function (done) { | ||
var db = new Penseur.Db('penseurtest'); | ||
db.establish(['test'], function (err) { | ||
expect(err).to.not.exist(); | ||
db.test.insert([{ a: 1 }, { id: 1, a: 2 }, { id: 2, a: 3 }, { a: 4 }, { a: 5 }, { id: 3, a: 6 }, { id: 4, a: 7 }], function (err, keys) { | ||
expect(err).to.not.exist(); | ||
expect(keys).to.have.length(7); | ||
expect(keys[1]).to.equal(1); | ||
expect(keys[2]).to.equal(2); | ||
expect(keys[5]).to.equal(3); | ||
expect(keys[6]).to.equal(4); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -284,0 +350,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
48740
1106