Comparing version 7.6.1 to 7.8.1
@@ -16,2 +16,6 @@ 'use strict'; | ||
if (criteria === null) { | ||
return table.raw; | ||
} | ||
// Optimize secondary index query | ||
@@ -18,0 +22,0 @@ |
@@ -166,7 +166,2 @@ 'use strict'; | ||
// this._settings has options passed with connection. | ||
// below array restricts which options will be configured in settings. | ||
// default does not have "user" or "password" which does not allow for | ||
// user & password authentication. | ||
const settings = this._connectionOptions || {}; | ||
@@ -526,3 +521,3 @@ if (!this._connectionOptions) { | ||
_run(request, options, table, action, inputs, callback, next) { | ||
_run(request, options, table, action, inputs, callback) { | ||
@@ -533,4 +528,2 @@ if (!this._connection) { | ||
next = next || callback; // next() must never return an error | ||
request.run(this._connection, options, (err, result) => { | ||
@@ -543,3 +536,3 @@ | ||
if (result === null) { | ||
return next(null, null); | ||
return callback(null, null); | ||
} | ||
@@ -556,3 +549,3 @@ | ||
return next(null, result); | ||
return callback(null, result); | ||
} | ||
@@ -563,3 +556,3 @@ | ||
const cursor = result; | ||
cursor.toArray((err, results) => { | ||
const finalize = (err, results) => { | ||
@@ -571,4 +564,19 @@ if (err) { | ||
cursor.close(); | ||
return next(null, results.length ? results : null); | ||
}); | ||
return callback(null, results && results.length ? results : null); | ||
}; | ||
if (!callback.each) { | ||
return cursor.toArray(finalize); | ||
} | ||
const each = (err, item) => { | ||
if (err) { | ||
return finalize(err); | ||
} | ||
callback.each(item); | ||
}; | ||
return cursor.each(each, finalize); | ||
}); | ||
@@ -575,0 +583,0 @@ } |
@@ -112,2 +112,6 @@ 'use strict'; | ||
if (options.chunks) { | ||
return this._chunks(criteria, options, callback); | ||
} | ||
const selection = Criteria.select(criteria, this); | ||
@@ -117,6 +121,62 @@ this._run(this._refine(selection, options), 'query', { criteria, options }, callback); | ||
_chunks(criteria, options, callback) { | ||
Hoek.assert(options.from === undefined && options.count === undefined, 'Cannot use chunks option with from or count'); | ||
Hoek.assert(callback.each, 'Must use apiece callback with each handler when specifying chunks option'); | ||
const selection = Criteria.select(criteria, this); | ||
const settings = Hoek.clone(options); | ||
delete settings.chunks; | ||
settings.count = options.chunks; | ||
if (!options.sort) { | ||
settings.sort = { key: this.primary, order: 'ascending' }; | ||
} | ||
let count = null; | ||
const step = (err, results) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (results) { | ||
results.forEach(step.each); | ||
} | ||
if (count !== null && | ||
count < options.chunks) { | ||
return callback(); | ||
} | ||
count = 0; | ||
if (settings.from === undefined) { | ||
settings.from = 0; | ||
} | ||
else { | ||
settings.from += options.chunks; | ||
} | ||
this._run(this._refine(selection, settings), 'query', { criteria, options }, step); | ||
}; | ||
step.each = (item) => { | ||
++count; | ||
return callback.each(item); | ||
}; | ||
return step(); | ||
} | ||
single(criteria, callback) { | ||
this._run(Criteria.select(criteria, this), 'single', criteria, callback, (ignore, result) => { | ||
this._run(Criteria.select(criteria, this), 'single', criteria, (err, result) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (!result) { | ||
@@ -160,4 +220,8 @@ return callback(null, null); | ||
this._run(this.raw.insert(wrapped, { conflict: options.merge ? 'update' : 'error' }), 'insert', diag, callback, (ignore, result) => { | ||
this._run(this.raw.insert(wrapped, { conflict: options.merge ? 'update' : 'error' }), 'insert', diag, (err, result) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
// Single item | ||
@@ -209,4 +273,8 @@ | ||
const opts = { returnChanges: !!postUnique }; | ||
this._run(this.raw.get(id).replace(wrapped, opts), 'update', diag, callback, (ignore, result) => { | ||
this._run(this.raw.get(id).replace(wrapped, opts), 'update', diag, (err, result) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (!postUnique) { | ||
@@ -227,4 +295,8 @@ return callback(null); | ||
const diag = { id, field, value }; | ||
this._run(this.raw.get(id).update(changes, { returnChanges: true }), 'next', diag, callback, (ignore, result) => { | ||
this._run(this.raw.get(id).update(changes, { returnChanges: true }), 'next', diag, (err, result) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (!result.replaced) { | ||
@@ -246,4 +318,8 @@ return this._error('next', 'No item found to update', diag, callback); | ||
this._run(selection.delete(), 'remove', criteria, callback, (ignore, result) => { | ||
this._run(selection.delete(), 'remove', criteria, (err, result) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (isSingle && | ||
@@ -402,5 +478,5 @@ !result.deleted) { | ||
_run(request, action, inputs, callback, next) { | ||
_run(request, action, inputs, callback) { | ||
return this._db._run(request, {}, this.name, action, inputs, callback, next); | ||
return this._db._run(request, {}, this.name, action, inputs, callback); | ||
} | ||
@@ -422,4 +498,10 @@ | ||
const message = (typeof err === 'string' ? err : 'Database error'); | ||
const message = (typeof err === 'string' ? err : err.message); | ||
const data = { error: err, table, action, inputs }; | ||
if (err instanceof Error) { | ||
data.error.stack = err.stack; | ||
data.error.message = err.message; | ||
} | ||
const error = Boom.internal(message, data); | ||
@@ -426,0 +508,0 @@ |
@@ -138,3 +138,5 @@ 'use strict'; | ||
if (item[field.rule.key] !== field.id) { | ||
return next(Boom.internal(`Action will violate unique restriction on ${item.id} in table ${field.rule.table.name}`)); | ||
err = `Action will violate unique restriction on ${item.id} in table ${field.rule.table.name}`; | ||
return next(err); | ||
} | ||
@@ -141,0 +143,0 @@ |
{ | ||
"name": "sikao", | ||
"description": "Fork of Penseur Lightweight RethinkDB wrapper", | ||
"version": "7.6.1", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "7.8.1", | ||
"author": "Jon Swenson <jswenson74@gmail.com>", | ||
@@ -23,4 +23,5 @@ "repository": "git://github.com/propadata/sikao", | ||
"devDependencies": { | ||
"apiece": "1.x.x", | ||
"code": "4.x.x", | ||
"lab": "11.x.x" | ||
"lab": "13.x.x" | ||
}, | ||
@@ -27,0 +28,0 @@ "scripts": { |
# sikao | 思考 | think | think about | ||
Fork of [penseur](https://github.com/hueniverse/penseur) Application-friendly RethinkDB client<br/> | ||
Needed some configurations tweaked for my use case so forked the project and made new package use case.<br/> | ||
Really the only change was configuring penseur to allow for user and password options. | ||
Default configs would not allow for user authentication with rethinkdb. | ||
Implementing and testing changes to penseur in this repo. Then, make PR requests to merge upstream.<br/> | ||
* Default configs would not allow for user authentication with rethinkdb. | ||
* Violate unique restriction error messages not returned. | ||
[](http://travis-ci.org/propadata/sikao) | ||
Sorry, the diff of this file is not supported yet
60334
1558
13
3