js-data-rethinkdb
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.4
@@ -0,1 +1,12 @@ | ||
##### 3.0.0-alpha.4 - 26 February 2016 | ||
###### Other | ||
- Finished JSDoc comments | ||
##### 3.0.0-alpha.3 - 26 February 2016 | ||
###### Backwards compatible API changes | ||
- Removed returnDeletedIds option | ||
- Added insertOpts, updateOpts, deleteOpts, and runOpts options | ||
##### 3.0.0-alpha.2 - 26 February 2016 | ||
@@ -2,0 +13,0 @@ |
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var jsData = require('js-data'); | ||
var rethinkdbdash = _interopDefault(require('rethinkdbdash')); | ||
var underscore = _interopDefault(require('mout/string/underscore')); | ||
@@ -29,3 +33,2 @@ var babelHelpers = {}; | ||
var rethinkdbdash = require('rethinkdbdash'); | ||
var addHiddenPropsToTarget = jsData.utils.addHiddenPropsToTarget; | ||
@@ -43,4 +46,2 @@ var fillIn = jsData.utils.fillIn; | ||
var underscore = require('mout/string/underscore'); | ||
var reserved = ['orderBy', 'sort', 'limit', 'offset', 'skip', 'where']; | ||
@@ -87,3 +88,3 @@ | ||
/** | ||
* TODO | ||
* RethinkDB authorization key. | ||
* | ||
@@ -96,3 +97,3 @@ * @name RethinkDBAdapter#authKey | ||
/** | ||
* TODO | ||
* Buffer size for connection pool. | ||
* | ||
@@ -106,3 +107,3 @@ * @name RethinkDBAdapter#bufferSize | ||
/** | ||
* TODO | ||
* Default database. | ||
* | ||
@@ -116,3 +117,3 @@ * @name RethinkDBAdapter#db | ||
/** | ||
* TODO | ||
* Whether to log debugging information. | ||
* | ||
@@ -126,3 +127,3 @@ * @name RethinkDBAdapter#debug | ||
/** | ||
* TODO | ||
* RethinkDB host. | ||
* | ||
@@ -136,3 +137,3 @@ * @name RethinkDBAdapter#host | ||
/** | ||
* TODO | ||
* Minimum connections in pool. | ||
* | ||
@@ -146,3 +147,3 @@ * @name RethinkDBAdapter#min | ||
/** | ||
* TODO | ||
* Maximum connections in pool. | ||
* | ||
@@ -156,3 +157,3 @@ * @name RethinkDBAdapter#max | ||
/** | ||
* TODO | ||
* RethinkDB port. | ||
* | ||
@@ -166,3 +167,3 @@ * @name RethinkDBAdapter#port | ||
/** | ||
* TODO | ||
* Whether to return a more detailed response object. | ||
* | ||
@@ -173,14 +174,10 @@ * @name RethinkDBAdapter#raw | ||
*/ | ||
raw: false, | ||
/** | ||
* TODO | ||
* | ||
* @name RethinkDBAdapter#returnDeletedIds | ||
* @type {boolean} | ||
* @default false | ||
*/ | ||
returnDeletedIds: false | ||
raw: false | ||
}; | ||
var INSERT_OPTS_DEFAULTS = {}; | ||
var UPDATE_OPTS_DEFAULTS = {}; | ||
var DELETE_OPTS_DEFAULTS = {}; | ||
var RUN_OPTS_DEFAULTS = {}; | ||
/** | ||
@@ -190,17 +187,30 @@ * RethinkDBAdapter class. | ||
* @example | ||
* import {DS} from 'js-data' | ||
* import RethinkDBAdapter from 'js-data-rethinkdb' | ||
* const store = new DS() | ||
* const adapter = new RethinkDBAdapter() | ||
* store.registerAdapter('rethinkdb', adapter, { 'default': true }) | ||
* // Use Container instead of DataStore on the server | ||
* import {Container} from 'js-data' | ||
* import RethinkdbDBAdapter from 'js-data-rethinkdb' | ||
* | ||
* // Create a store to hold your Mappers | ||
* const store = new Container() | ||
* | ||
* // Create an instance of RethinkdbDBAdapter with default settings | ||
* const adapter = new RethinkdbDBAdapter() | ||
* | ||
* // Mappers in "store" will use the RethinkDB adapter by default | ||
* store.registerAdapter('rethinkdb', adapter, { default: true }) | ||
* | ||
* // Create a Mapper that maps to a "user" table | ||
* store.defineMapper('user') | ||
* | ||
* @class RethinkDBAdapter | ||
* @param {Object} [opts] Configuration opts. | ||
* @param {string} [opts.host='localhost'] TODO | ||
* @param {number} [opts.port=28015] TODO | ||
* @param {string} [opts.authKey=''] TODO | ||
* @param {string} [opts.db='test'] TODO | ||
* @param {number} [opts.min=10] TODO | ||
* @param {number} [opts.max=50] TODO | ||
* @param {number} [opts.bufferSize=10] TODO | ||
* @param {string} [opts.authKey=""] RethinkDB authorization key. | ||
* @param {number} [opts.bufferSize=10] Buffer size for connection pool. | ||
* @param {string} [opts.db="test"] Default database. | ||
* @param {boolean} [opts.debug=false] Whether to log debugging information. | ||
* @param {string} [opts.host="localhost"] RethinkDB host. | ||
* @param {number} [opts.max=50] Maximum connections in pool. | ||
* @param {number} [opts.min=10] Minimum connections in pool. | ||
* @param {number} [opts.port=28015] RethinkDB port. | ||
* @param {boolean} [opts.raw=false] Whether to return detailed result objects | ||
* instead of just record data. | ||
*/ | ||
@@ -212,2 +222,50 @@ function RethinkDBAdapter(opts) { | ||
fillIn(self, opts); | ||
/** | ||
* Default options to pass to r#insert. | ||
* | ||
* @name RethinkDBAdapter#insertOpts | ||
* @type {Object} | ||
* @default {} | ||
*/ | ||
self.insertOpts || (self.insertOpts = {}); | ||
fillIn(self.insertOpts, INSERT_OPTS_DEFAULTS); | ||
/** | ||
* Default options to pass to r#update. | ||
* | ||
* @name RethinkDBAdapter#updateOpts | ||
* @type {Object} | ||
* @default {} | ||
*/ | ||
self.updateOpts || (self.updateOpts = {}); | ||
fillIn(self.updateOpts, UPDATE_OPTS_DEFAULTS); | ||
/** | ||
* Default options to pass to r#delete. | ||
* | ||
* @name RethinkDBAdapter#deleteOpts | ||
* @type {Object} | ||
* @default {} | ||
*/ | ||
self.deleteOpts || (self.deleteOpts = {}); | ||
fillIn(self.deleteOpts, DELETE_OPTS_DEFAULTS); | ||
/** | ||
* Default options to pass to r#run. | ||
* | ||
* @name RethinkDBAdapter#runOpts | ||
* @type {Object} | ||
* @default {} | ||
*/ | ||
self.runOpts || (self.runOpts = {}); | ||
fillIn(self.runOpts, RUN_OPTS_DEFAULTS); | ||
/** | ||
* The rethinkdbdash instance used by this adapter. Use this directly when you | ||
* need to write custom queries. | ||
* | ||
* @name RethinkDBAdapter#r | ||
* @type {Object} | ||
*/ | ||
self.r = rethinkdbdash(opts); | ||
@@ -351,4 +409,4 @@ self.databases = {}; | ||
}, | ||
selectTable: function selectTable(Resource, opts) { | ||
return this.selectDb(opts).table(Resource.table || underscore(Resource.name)); | ||
selectTable: function selectTable(mapper, opts) { | ||
return this.selectDb(opts).table(mapper.table || underscore(mapper.name)); | ||
}, | ||
@@ -482,3 +540,6 @@ filterSequence: function filterSequence(sequence, params) { | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {Object} [opts.insertOpts] Options to pass to r#insert. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -492,3 +553,3 @@ */ | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeCreate lifecycle hook | ||
@@ -500,3 +561,5 @@ op = opts.op = 'beforeCreate'; | ||
_props = isUndefined(_props) ? props : _props; | ||
return self.selectTable(mapper, opts).insert(_props, { returnChanges: true }).run(); | ||
var insertOpts = self.getOpt('insertOpts', opts); | ||
insertOpts.returnChanges = true; | ||
return self.selectTable(mapper, opts).insert(_props, insertOpts).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
@@ -517,3 +580,3 @@ self._handleErrors(cursor); | ||
result.created = record ? 1 : 0; | ||
return self.getRaw(opts) ? result : result.data; | ||
return self.getOpt('raw', opts) ? result : result.data; | ||
}); | ||
@@ -532,3 +595,6 @@ }); | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {Object} [opts.insertOpts] Options to pass to r#insert. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -542,3 +608,3 @@ */ | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeCreateMany lifecycle hook | ||
@@ -550,3 +616,5 @@ op = opts.op = 'beforeCreateMany'; | ||
_props = isUndefined(_props) ? props : _props; | ||
return self.selectTable(mapper, opts).insert(_props, { returnChanges: true }).run(); | ||
var insertOpts = self.getOpt('insertOpts', opts); | ||
insertOpts.returnChanges = true; | ||
return self.selectTable(mapper, opts).insert(_props, insertOpts).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
@@ -569,3 +637,3 @@ self._handleErrors(cursor); | ||
result.created = records.length; | ||
return self.getRaw(opts) ? result : result.data; | ||
return self.getOpt('raw', opts) ? result : result.data; | ||
}); | ||
@@ -584,5 +652,6 @@ }); | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {boolean} [opts.returnDeletedIds=false] Whether to return the | ||
* primary keys of any deleted records. | ||
* @param {Object} [opts.deleteOpts] Options to pass to r#delete. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -594,5 +663,4 @@ */ | ||
opts || (opts = {}); | ||
var returnDeletedIds = isUndefined(opts.returnDeletedIds) ? self.returnDeletedIds : !!opts.returnDeletedIds; | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeDestroy lifecycle hook | ||
@@ -604,18 +672,12 @@ op = opts.op = 'beforeDestroy'; | ||
self.dbg(op, id, opts); | ||
return self.selectTable(mapper, opts).get(id).delete().run(); | ||
return self.selectTable(mapper, opts).get(id).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
var deleted = 0; | ||
if (cursor && cursor.deleted && returnDeletedIds) { | ||
deleted = cursor.deleted; | ||
} | ||
// afterDestroy lifecycle hook | ||
op = opts.op = 'afterDestroy'; | ||
return resolve(self[op](mapper, id, opts, deleted ? id : undefined)).then(function (_id) { | ||
return resolve(self[op](mapper, id, opts, cursor)).then(function (_cursor) { | ||
// Allow for re-assignment from lifecycle hook | ||
id = isUndefined(_id) && deleted ? id : _id; | ||
var result = {}; | ||
fillIn(result, cursor); | ||
result.data = id; | ||
return self.getRaw(opts) ? result : result.data; | ||
return isUndefined(_cursor) ? cursor : _cursor; | ||
}); | ||
}).then(function (cursor) { | ||
return self.getOpt('raw', opts) ? cursor : undefined; | ||
}); | ||
@@ -633,5 +695,6 @@ }, | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {boolean} [opts.returnDeletedIds=false] Whether to return the | ||
* primary keys of any deleted records. | ||
* @param {Object} [opts.deleteOpts] Options to pass to r#delete. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -641,9 +704,7 @@ */ | ||
var self = this; | ||
var idAttribute = mapper.idAttribute; | ||
var op = undefined; | ||
query || (query = {}); | ||
opts || (opts = {}); | ||
var returnDeletedIds = isUndefined(opts.returnDeletedIds) ? self.returnDeletedIds : !!opts.returnDeletedIds; | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeDestroyAll lifecycle hook | ||
@@ -655,27 +716,12 @@ op = opts.op = 'beforeDestroyAll'; | ||
self.dbg(op, query, opts); | ||
return self.filterSequence(self.selectTable(mapper, opts), query).delete({ returnChanges: returnDeletedIds }).merge(function (cursor) { | ||
return { | ||
changes: cursor('changes').default([]).map(function (record) { | ||
return record('old_val').default({})(idAttribute).default({}); | ||
}).filter(function (id) { | ||
return id; | ||
}) | ||
}; | ||
}).run(); | ||
return self.filterSequence(self.selectTable(mapper, opts), query).delete(self.getOpt('deleteOpts', opts)).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
var deletedIds = undefined; | ||
if (cursor && cursor.changes && returnDeletedIds) { | ||
deletedIds = cursor.changes; | ||
delete cursor.changes; | ||
} | ||
// afterDestroyAll lifecycle hook | ||
op = opts.op = 'afterDestroyAll'; | ||
return resolve(self[op](mapper, query, opts, deletedIds)).then(function (_deletedIds) { | ||
return resolve(self[op](mapper, query, opts, cursor)).then(function (_cursor) { | ||
// Allow for re-assignment from lifecycle hook | ||
deletedIds = isUndefined(_deletedIds) ? deletedIds : _deletedIds; | ||
var result = {}; | ||
fillIn(result, cursor); | ||
result.data = deletedIds; | ||
return self.getRaw(opts) ? result : result.data; | ||
return isUndefined(_cursor) ? cursor : _cursor; | ||
}); | ||
}).then(function (cursor) { | ||
return self.getOpt('raw', opts) ? cursor : undefined; | ||
}); | ||
@@ -686,3 +732,3 @@ }, | ||
/** | ||
* TODO | ||
* Return the foreignKey from the given record for the provided relationship. | ||
* | ||
@@ -696,3 +742,3 @@ * There may be reasons why you may want to override this method, like when | ||
*/ | ||
makeHasManyForeignKey: function makeHasManyForeignKey(Resource, def, record) { | ||
makeHasManyForeignKey: function makeHasManyForeignKey(mapper, def, record) { | ||
return def.getForeignKey(record); | ||
@@ -703,3 +749,3 @@ }, | ||
/** | ||
* TODO | ||
* Load a hasMany relationship. | ||
* | ||
@@ -710,3 +756,3 @@ * @name RethinkDBAdapter#loadHasMany | ||
*/ | ||
loadHasMany: function loadHasMany(Resource, def, records, __opts) { | ||
loadHasMany: function loadHasMany(mapper, def, records, __opts) { | ||
var self = this; | ||
@@ -720,3 +766,3 @@ var singular = false; | ||
var IDs = records.map(function (record) { | ||
return self.makeHasManyForeignKey(Resource, def, record); | ||
return self.makeHasManyForeignKey(mapper, def, record); | ||
}); | ||
@@ -741,3 +787,3 @@ var query = {}; | ||
relatedItems.forEach(function (relatedItem) { | ||
if (get(relatedItem, def.foreignKey) === record[Resource.idAttribute]) { | ||
if (get(relatedItem, def.foreignKey) === record[mapper.idAttribute]) { | ||
attached.push(relatedItem); | ||
@@ -754,3 +800,3 @@ } | ||
/** | ||
* TODO | ||
* Load a hasOne relationship. | ||
* | ||
@@ -761,7 +807,7 @@ * @name RethinkDBAdapter#loadHasOne | ||
*/ | ||
loadHasOne: function loadHasOne(Resource, def, records, __opts) { | ||
loadHasOne: function loadHasOne(mapper, def, records, __opts) { | ||
if (isObject(records) && !isArray(records)) { | ||
records = [records]; | ||
} | ||
return this.loadHasMany(Resource, def, records, __opts).then(function () { | ||
return this.loadHasMany(mapper, def, records, __opts).then(function () { | ||
records.forEach(function (record) { | ||
@@ -778,3 +824,3 @@ var relatedData = def.getLocalField(record); | ||
/** | ||
* TODO | ||
* Return the foreignKey from the given record for the provided relationship. | ||
* | ||
@@ -785,3 +831,3 @@ * @name RethinkDBAdapter#makeBelongsToForeignKey | ||
*/ | ||
makeBelongsToForeignKey: function makeBelongsToForeignKey(Resource, def, record) { | ||
makeBelongsToForeignKey: function makeBelongsToForeignKey(mapper, def, record) { | ||
return def.getForeignKey(record); | ||
@@ -792,3 +838,3 @@ }, | ||
/** | ||
* TODO | ||
* Load a belongsTo relationship. | ||
* | ||
@@ -845,4 +891,6 @@ * @name RethinkDBAdapter#loadBelongsTo | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {string[]} [opts.with=[]] TODO | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @param {string[]} [opts.with=[]] Relations to eager load. | ||
* @return {Promise} | ||
@@ -857,5 +905,4 @@ */ | ||
var table = mapper.table || underscore(mapper.name); | ||
var relationList = mapper.relationList || []; | ||
var tasks = [self.waitForTable(table, opts)]; | ||
var tasks = [self.waitForTable(mapper, opts)]; | ||
@@ -879,7 +926,7 @@ relationList.forEach(function (def) { | ||
op = opts.op = 'beforeFind'; | ||
return resolve(self[op](mapper, id, opts)).then(function () { | ||
op = opts.op = 'find'; | ||
self.dbg(op, id, opts); | ||
return self.selectTable(mapper, opts).get(id).run(); | ||
}); | ||
return resolve(self[op](mapper, id, opts)); | ||
}).then(function () { | ||
op = opts.op = 'find'; | ||
self.dbg(op, id, opts); | ||
return self.selectTable(mapper, opts).get(id).run(self.getOpt('runOpts', opts)); | ||
}).then(function (_record) { | ||
@@ -939,3 +986,3 @@ if (!_record) { | ||
record = isUndefined(_record) ? record : _record; | ||
return self.getRaw(opts) ? { | ||
return self.getOpt('raw', opts) ? { | ||
data: record, | ||
@@ -957,4 +1004,6 @@ found: record ? 1 : 0 | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {string[]} [opts.with=[]] TODO | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @param {string[]} [opts.with=[]] Relations to eager load. | ||
* @return {Promise} | ||
@@ -969,5 +1018,4 @@ */ | ||
var op = undefined; | ||
var table = mapper.table || underscore(mapper.name); | ||
var relationList = mapper.relationList || []; | ||
var tasks = [self.waitForTable(table, opts)]; | ||
var tasks = [self.waitForTable(mapper, opts)]; | ||
@@ -995,3 +1043,3 @@ relationList.forEach(function (def) { | ||
self.dbg(op, query, opts); | ||
return self.filterSequence(self.selectTable(mapper, opts), query).run(); | ||
return self.filterSequence(self.selectTable(mapper, opts), query).run(self.getOpt('runOpts', opts)); | ||
}).then(function (_records) { | ||
@@ -1074,3 +1122,3 @@ records = _records; | ||
records = isUndefined(_records) ? records : _records; | ||
return self.getRaw(opts) ? { | ||
return self.getOpt('raw', opts) ? { | ||
data: records, | ||
@@ -1085,10 +1133,14 @@ found: records.length | ||
/** | ||
* TODO | ||
* Resolve the value of the specified option based on the given options and | ||
* this adapter's settings. | ||
* | ||
* @name RethinkDBAdapter#getRaw | ||
* @name RethinkDBAdapter#getOpt | ||
* @method | ||
* @param {string} opt The name of the option. | ||
* @param {Object} [opts] Configuration options. | ||
* @return {*} The value of the specified option. | ||
*/ | ||
getRaw: function getRaw(opts) { | ||
getOpt: function getOpt(opt, opts) { | ||
opts || (opts = {}); | ||
return !!(isUndefined(opts.raw) ? this.raw : opts.raw); | ||
return isUndefined(opts[opt]) ? this[opt] : opts[opt]; | ||
}, | ||
@@ -1098,3 +1150,3 @@ | ||
/** | ||
* TODO | ||
* Logging utility method. | ||
* | ||
@@ -1138,3 +1190,6 @@ * @name RethinkDBAdapter#log | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {Object} [opts.updateOpts] Options to pass to r#update. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -1148,3 +1203,3 @@ */ | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeUpdate lifecycle hook | ||
@@ -1156,3 +1211,5 @@ op = opts.op = 'beforeUpdate'; | ||
_props = isUndefined(_props) ? props : _props; | ||
return self.selectTable(mapper, opts).get(id).update(_props, { returnChanges: true }).run(); | ||
var updateOpts = self.getOpt('updateOpts', opts); | ||
updateOpts.returnChanges = true; | ||
return self.selectTable(mapper, opts).get(id).update(_props, updateOpts).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
@@ -1176,3 +1233,3 @@ var record = undefined; | ||
result.updated = record ? 1 : 0; | ||
return self.getRaw(opts) ? result : result.data; | ||
return self.getOpt('raw', opts) ? result : result.data; | ||
}); | ||
@@ -1192,3 +1249,6 @@ }); | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {Object} [opts.updateOpts] Options to pass to r#update. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -1203,3 +1263,3 @@ */ | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeUpdateAll lifecycle hook | ||
@@ -1211,3 +1271,5 @@ op = opts.op = 'beforeUpdateAll'; | ||
_props = isUndefined(_props) ? props : _props; | ||
return self.filterSequence(self.selectTable(mapper, opts), query).update(_props, { returnChanges: true }).run(); | ||
var updateOpts = self.getOpt('updateOpts', opts); | ||
updateOpts.returnChanges = true; | ||
return self.filterSequence(self.selectTable(mapper, opts), query).update(_props, updateOpts).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
@@ -1230,3 +1292,3 @@ var records = []; | ||
result.updated = records.length; | ||
return self.getRaw(opts) ? result : result.data; | ||
return self.getOpt('raw', opts) ? result : result.data; | ||
}); | ||
@@ -1245,3 +1307,6 @@ }); | ||
* @param {Object} [opts] Configuration options. | ||
* @param {boolean} [opts.raw=false] TODO | ||
* @param {Object} [opts.insertOpts] Options to pass to r#insert. | ||
* @param {boolean} [opts.raw=false] Whether to return a more detailed | ||
* response object. | ||
* @param {Object} [opts.runOpts] Options to pass to r#run. | ||
* @return {Promise} | ||
@@ -1260,3 +1325,3 @@ */ | ||
return self.waitForTable(mapper.table || underscore(mapper.name), opts).then(function () { | ||
return self.waitForTable(mapper, opts).then(function () { | ||
// beforeUpdateMany lifecycle hook | ||
@@ -1268,3 +1333,6 @@ op = opts.op = 'beforeUpdateMany'; | ||
_records = isUndefined(_records) ? records : _records; | ||
return self.selectTable(mapper, opts).insert(_records, { returnChanges: true, conflict: 'update' }).run(); | ||
var insertOpts = self.getOpt('insertOpts', opts); | ||
insertOpts.returnChanges = true; | ||
insertOpts.conflict = 'update'; | ||
return self.selectTable(mapper, opts).insert(_records, insertOpts).run(self.getOpt('runOpts', opts)); | ||
}).then(function (cursor) { | ||
@@ -1288,9 +1356,10 @@ var updatedRecords = undefined; | ||
result.updated = records.length; | ||
return self.getRaw(opts) ? result : result.data; | ||
return self.getOpt('raw', opts) ? result : result.data; | ||
}); | ||
}); | ||
}, | ||
waitForTable: function waitForTable(table, options) { | ||
waitForTable: function waitForTable(mapper, options) { | ||
var _this = this; | ||
var table = isString(mapper) ? mapper : mapper.table || underscore(mapper.name); | ||
options = options || {}; | ||
@@ -1297,0 +1366,0 @@ var db = isUndefined(options.db) ? this.db : options.db; |
{ | ||
"name": "js-data-rethinkdb", | ||
"description": "RethinkDB adapter for js-data.", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.4", | ||
"homepage": "https://github.com/js-data/js-data-rethinkdb", | ||
@@ -39,5 +39,6 @@ "repository": { | ||
"lint": "standard src/index.js mocha.start.js test/**/*.js", | ||
"mocha": "mocha -t 20000 -R dot -r source-map-support/register mocha.start.js test/**/*.js", | ||
"cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 20000 -R dot -r source-map-support/register mocha.start.js test/**/*.js", | ||
"test": "npm run lint && npm run bundle && npm run cover", | ||
"build": "npm run lint && npm run bundle", | ||
"mocha": "mocha -t 20000 -R dot -r source-map-support/register mocha.start.js", | ||
"cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 20000 -R dot -r source-map-support/register mocha.start.js", | ||
"test": "npm run build && npm run cover", | ||
"release": "npm test && npm run doc && node scripts/authors.js", | ||
@@ -56,7 +57,4 @@ "ci": "npm run test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true" | ||
"babel-eslint": "5.0.0", | ||
"babel-plugin-syntax-async-functions": "6.5.0", | ||
"babel-plugin-transform-regenerator": "6.5.2", | ||
"babel-polyfill": "6.5.0", | ||
"babel-preset-es2015-rollup": "1.1.1", | ||
"babel-preset-stage-0": "6.5.0", | ||
"chai": "3.5.0", | ||
@@ -67,3 +65,3 @@ "codacy-coverage": "1.1.3", | ||
"istanbul": "0.4.2", | ||
"js-data-adapter-tests": "^2.0.0-alpha.7", | ||
"js-data-adapter-tests": "^2.0.0-alpha.9", | ||
"jsdoc": "3.4.0", | ||
@@ -70,0 +68,0 @@ "mocha": "2.4.5", |
@@ -28,17 +28,31 @@ <img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="96" height="96" /> | ||
## Quick Start | ||
`npm install --save js-data js-data-rethinkdb`. | ||
`npm install --save js-data js-data-rethinkdb rethinkdbdash`. | ||
```js | ||
// Use Container instead of DataStore on the server | ||
import {Container} from 'js-data' | ||
import RethinkDBAdapter from 'js-data-rethinkdb' | ||
// Create a store to hold your Mappers | ||
const store = new Container() | ||
// Create an instance of RethinkDBAdapter with default settings | ||
const adapter = new RethinkDBAdapter() | ||
// "store" will now use the RethinkDB adapter for all async operations | ||
store.registerAdapter('rethinkdb', adapter, { default: true }); | ||
// Mappers in "store" will use the RethinkDB adapter by default | ||
store.registerAdapter('rethinkdb', adapter, { default: true }) | ||
store.defineMapper('user'); | ||
// Create a Mapper that maps to a "user" table | ||
store.defineMapper('user') | ||
``` | ||
```js | ||
async function findAllAdminUsers () { | ||
// Find all users where "user.role" == "admin" | ||
return await store.findAll('user', { | ||
role: 'admin' | ||
}) | ||
} | ||
``` | ||
## Example App | ||
@@ -45,0 +59,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
133664
16
1299
103