Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-data-rethinkdb

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data-rethinkdb - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

.babelrc

5

CHANGELOG.md

@@ -0,1 +1,6 @@

##### 2.2.0 - 25 February 2016
###### Other
- General improvements
##### 2.1.0 - 26 October 2015

@@ -2,0 +7,0 @@

1225

dist/js-data-rethinkdb.js

@@ -1,545 +0,790 @@

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
'use strict';
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
var babelHelpers = {};
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
babelHelpers.classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
babelHelpers.defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
return obj;
};
/******/ // Flag the module as loaded
/******/ module.loaded = true;
babelHelpers;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
var rethinkdbdash = require('rethinkdbdash');
var JSData = require('js-data');
var DSUtils = JSData.DSUtils;
var upperCase = DSUtils.upperCase;
var contains = DSUtils.contains;
var forOwn = DSUtils.forOwn;
var isEmpty = DSUtils.isEmpty;
var keys = DSUtils.keys;
var deepMixIn = DSUtils.deepMixIn;
var forEach = DSUtils.forEach;
var isObject = DSUtils.isObject;
var isString = DSUtils.isString;
var removeCircular = DSUtils.removeCircular;
var omit = DSUtils.omit;
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
var underscore = require('mout/string/underscore');
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
var reserved = ['orderBy', 'sort', 'limit', 'offset', 'skip', 'where'];
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
var addHiddenPropsToTarget = function addHiddenPropsToTarget(target, props) {
DSUtils.forOwn(props, function (value, key) {
props[key] = {
writable: true,
value: value
};
});
Object.defineProperties(target, props);
};
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
var fillIn = function fillIn(dest, src) {
DSUtils.forOwn(src, function (value, key) {
if (!dest.hasOwnProperty(key) || dest[key] === undefined) {
dest[key] = value;
}
});
};
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var unique = function unique(array) {
var seen = {};
var final = [];
array.forEach(function (item) {
if (item in seen) {
return;
}
final.push(item);
seen[item] = 0;
});
return final;
};
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Defaults = function Defaults() {
babelHelpers.classCallCheck(this, Defaults);
};
var rethinkdbdash = __webpack_require__(1);
var JSData = __webpack_require__(2);
var DSUtils = JSData.DSUtils;
var upperCase = DSUtils.upperCase;
var contains = DSUtils.contains;
var forOwn = DSUtils.forOwn;
var isEmpty = DSUtils.isEmpty;
var keys = DSUtils.keys;
var deepMixIn = DSUtils.deepMixIn;
var forEach = DSUtils.forEach;
var isObject = DSUtils.isObject;
var isArray = DSUtils.isArray;
var isString = DSUtils.isString;
var removeCircular = DSUtils.removeCircular;
var omit = DSUtils.omit;
addHiddenPropsToTarget(Defaults.prototype, {
host: 'localhost',
port: 28015,
authKey: '',
db: 'test',
min: 10,
max: 50,
bufferSize: 10
});
var underscore = __webpack_require__(3);
/**
* 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 })
*
* @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
*/
function RethinkDBAdapter(opts) {
var self = this;
var Defaults = function Defaults() {
_classCallCheck(this, Defaults);
};
self.defaults = new Defaults();
deepMixIn(self.defaults, opts);
fillIn(self, opts);
self.r = rethinkdbdash(self.defaults);
self.databases = {};
self.tables = {};
self.indices = {};
}
Defaults.prototype.host = 'localhost';
Defaults.prototype.port = 28015;
Defaults.prototype.authKey = '';
Defaults.prototype.db = 'test';
Defaults.prototype.min = 10;
Defaults.prototype.max = 50;
Defaults.prototype.bufferSize = 10;
addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
_handleErrors: function _handleErrors(cursor) {
if (cursor && cursor.errors > 0) {
if (cursor.first_error) {
throw new Error(cursor.first_error);
}
throw new Error('Unknown RethinkDB Error');
}
},
selectTable: function selectTable(Resource, opts) {
return this.r.db(opts.db || this.defaults.db).table(Resource.table || underscore(Resource.name));
},
filterSequence: function filterSequence(sequence, params) {
var r = this.r;
params = params || {};
params.where = params.where || {};
params.orderBy = params.orderBy || params.sort;
params.skip = params.skip || params.offset;
var reserved = ['orderBy', 'sort', 'limit', 'offset', 'skip', 'where'];
forEach(keys(params), function (k) {
var v = params[k];
if (!contains(reserved, k)) {
if (isObject(v)) {
params.where[k] = v;
} else {
params.where[k] = {
'==': v
};
}
delete params[k];
}
});
var DSRethinkDBAdapter = (function () {
function DSRethinkDBAdapter(options) {
_classCallCheck(this, DSRethinkDBAdapter);
var query = sequence;
options = options || {};
this.defaults = new Defaults();
deepMixIn(this.defaults, options);
this.r = rethinkdbdash(this.defaults);
this.databases = {};
this.tables = {};
this.indices = {};
}
if (!isEmpty(params.where)) {
query = query.filter(function (row) {
var subQuery = undefined;
forOwn(params.where, function (criteria, field) {
if (!isObject(criteria)) {
criteria = { '==': criteria };
}
forOwn(criteria, function (v, op) {
if (op === '==' || op === '===') {
subQuery = subQuery ? subQuery.and(row(field).default(null).eq(v)) : row(field).default(null).eq(v);
} else if (op === '!=' || op === '!==') {
subQuery = subQuery ? subQuery.and(row(field).default(null).ne(v)) : row(field).default(null).ne(v);
} else if (op === '>') {
subQuery = subQuery ? subQuery.and(row(field).default(null).gt(v)) : row(field).default(null).gt(v);
} else if (op === '>=') {
subQuery = subQuery ? subQuery.and(row(field).default(null).ge(v)) : row(field).default(null).ge(v);
} else if (op === '<') {
subQuery = subQuery ? subQuery.and(row(field).default(null).lt(v)) : row(field).default(null).lt(v);
} else if (op === '<=') {
subQuery = subQuery ? subQuery.and(row(field).default(null).le(v)) : row(field).default(null).le(v);
} else if (op === 'isectEmpty') {
subQuery = subQuery ? subQuery.and(row(field).default([]).setIntersection(r.expr(v).default([])).count().eq(0)) : row(field).default([]).setIntersection(r.expr(v).default([])).count().eq(0);
} else if (op === 'isectNotEmpty') {
subQuery = subQuery ? subQuery.and(row(field).default([]).setIntersection(r.expr(v).default([])).count().ne(0)) : row(field).default([]).setIntersection(r.expr(v).default([])).count().ne(0);
} else if (op === 'in') {
subQuery = subQuery ? subQuery.and(r.expr(v).default(r.expr([])).contains(row(field).default(null))) : r.expr(v).default(r.expr([])).contains(row(field).default(null));
} else if (op === 'notIn') {
subQuery = subQuery ? subQuery.and(r.expr(v).default(r.expr([])).contains(row(field).default(null)).not()) : r.expr(v).default(r.expr([])).contains(row(field).default(null)).not();
} else if (op === '|==' || op === '|===') {
subQuery = subQuery ? subQuery.or(row(field).default(null).eq(v)) : row(field).default(null).eq(v);
} else if (op === '|!=' || op === '|!==') {
subQuery = subQuery ? subQuery.or(row(field).default(null).ne(v)) : row(field).default(null).ne(v);
} else if (op === '|>') {
subQuery = subQuery ? subQuery.or(row(field).default(null).gt(v)) : row(field).default(null).gt(v);
} else if (op === '|>=') {
subQuery = subQuery ? subQuery.or(row(field).default(null).ge(v)) : row(field).default(null).ge(v);
} else if (op === '|<') {
subQuery = subQuery ? subQuery.or(row(field).default(null).lt(v)) : row(field).default(null).lt(v);
} else if (op === '|<=') {
subQuery = subQuery ? subQuery.or(row(field).default(null).le(v)) : row(field).default(null).le(v);
} else if (op === '|isectEmpty') {
subQuery = subQuery ? subQuery.or(row(field).default([]).setIntersection(r.expr(v).default([])).count().eq(0)) : row(field).default([]).setIntersection(r.expr(v).default([])).count().eq(0);
} else if (op === '|isectNotEmpty') {
subQuery = subQuery ? subQuery.or(row(field).default([]).setIntersection(r.expr(v).default([])).count().ne(0)) : row(field).default([]).setIntersection(r.expr(v).default([])).count().ne(0);
} else if (op === '|in') {
subQuery = subQuery ? subQuery.or(r.expr(v).default(r.expr([])).contains(row(field).default(null))) : r.expr(v).default(r.expr([])).contains(row(field).default(null));
} else if (op === '|notIn') {
subQuery = subQuery ? subQuery.or(r.expr(v).default(r.expr([])).contains(row(field).default(null)).not()) : r.expr(v).default(r.expr([])).contains(row(field).default(null)).not();
}
});
});
return subQuery;
});
}
_createClass(DSRethinkDBAdapter, [{
key: 'selectTable',
value: function selectTable(resourceConfig, options) {
return this.r.db(options.db || this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name));
}
}, {
key: 'filterSequence',
value: function filterSequence(sequence, params) {
var r = this.r;
params = params || {};
params.where = params.where || {};
params.orderBy = params.orderBy || params.sort;
params.skip = params.skip || params.offset;
if (params.orderBy) {
if (isString(params.orderBy)) {
params.orderBy = [[params.orderBy, 'asc']];
}
for (var i = 0; i < params.orderBy.length; i++) {
if (isString(params.orderBy[i])) {
params.orderBy[i] = [params.orderBy[i], 'asc'];
}
query = upperCase(params.orderBy[i][1]) === 'DESC' ? query.orderBy(r.desc(params.orderBy[i][0])) : query.orderBy(params.orderBy[i][0]);
}
}
forEach(keys(params), function (k) {
var v = params[k];
if (!contains(reserved, k)) {
if (isObject(v)) {
params.where[k] = v;
} else {
params.where[k] = {
'==': v
};
}
delete params[k];
}
});
if (params.skip) {
query = query.skip(+params.skip);
}
var query = sequence;
if (params.limit) {
query = query.limit(+params.limit);
}
if (!isEmpty(params.where)) {
query = query.filter(function (row) {
var subQuery = undefined;
forOwn(params.where, function (criteria, field) {
if (!isObject(criteria)) {
criteria = { '==': criteria };
}
forOwn(criteria, function (v, op) {
if (op === '==' || op === '===') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).eq(v)) : row(field)['default'](null).eq(v);
} else if (op === '!=' || op === '!==') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).ne(v)) : row(field)['default'](null).ne(v);
} else if (op === '>') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).gt(v)) : row(field)['default'](null).gt(v);
} else if (op === '>=') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).ge(v)) : row(field)['default'](null).ge(v);
} else if (op === '<') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).lt(v)) : row(field)['default'](null).lt(v);
} else if (op === '<=') {
subQuery = subQuery ? subQuery.and(row(field)['default'](null).le(v)) : row(field)['default'](null).le(v);
} else if (op === 'isectEmpty') {
subQuery = subQuery ? subQuery.and(row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().eq(0)) : row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().eq(0);
} else if (op === 'isectNotEmpty') {
subQuery = subQuery ? subQuery.and(row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().ne(0)) : row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().ne(0);
} else if (op === 'in') {
subQuery = subQuery ? subQuery.and(r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null))) : r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null));
} else if (op === 'notIn') {
subQuery = subQuery ? subQuery.and(r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null)).not()) : r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null)).not();
} else if (op === '|==' || op === '|===') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).eq(v)) : row(field)['default'](null).eq(v);
} else if (op === '|!=' || op === '|!==') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).ne(v)) : row(field)['default'](null).ne(v);
} else if (op === '|>') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).gt(v)) : row(field)['default'](null).gt(v);
} else if (op === '|>=') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).ge(v)) : row(field)['default'](null).ge(v);
} else if (op === '|<') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).lt(v)) : row(field)['default'](null).lt(v);
} else if (op === '|<=') {
subQuery = subQuery ? subQuery.or(row(field)['default'](null).le(v)) : row(field)['default'](null).le(v);
} else if (op === '|isectEmpty') {
subQuery = subQuery ? subQuery.or(row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().eq(0)) : row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().eq(0);
} else if (op === '|isectNotEmpty') {
subQuery = subQuery ? subQuery.or(row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().ne(0)) : row(field)['default']([]).setIntersection(r.expr(v)['default']([])).count().ne(0);
} else if (op === '|in') {
subQuery = subQuery ? subQuery.or(r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null))) : r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null));
} else if (op === '|notIn') {
subQuery = subQuery ? subQuery.or(r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null)).not()) : r.expr(v)['default'](r.expr([])).contains(row(field)['default'](null)).not();
}
});
});
return subQuery;
});
}
return query;
},
waitForDb: function waitForDb(opts) {
var self = this;
opts = opts || {};
var db = opts.db || self.defaults.db;
if (!self.databases[db]) {
self.databases[db] = self.r.branch(self.r.dbList().contains(db), true, self.r.dbCreate(db)).run();
}
return self.databases[db];
},
if (params.orderBy) {
if (isString(params.orderBy)) {
params.orderBy = [[params.orderBy, 'asc']];
}
for (var i = 0; i < params.orderBy.length; i++) {
if (isString(params.orderBy[i])) {
params.orderBy[i] = [params.orderBy[i], 'asc'];
}
query = upperCase(params.orderBy[i][1]) === 'DESC' ? query.orderBy(r.desc(params.orderBy[i][0])) : query.orderBy(params.orderBy[i][0]);
}
}
if (params.skip) {
query = query.skip(params.skip);
}
/**
* Create a new record.
*
* @name RethinkDBAdapter#create
* @method
* @param {Object} Resource The Resource.
* @param {Object} props The record to be created.
* @param {Object} [opts] Configuration options.
* @return {Promise}
*/
create: function create(Resource, props, opts) {
var self = this;
props = removeCircular(omit(props, Resource.relationFields || []));
opts || (opts = {});
if (params.limit) {
query = query.limit(params.limit);
}
return self.waitForTable(Resource.table || underscore(Resource.name), opts).then(function () {
return self.selectTable(Resource, opts).insert(props, { returnChanges: true }).run();
}).then(function (cursor) {
self._handleErrors(cursor);
return cursor.changes[0].new_val;
});
},
return query;
}
}, {
key: 'waitForDb',
value: function waitForDb(options) {
options = options || {};
var db = options.db || this.defaults.db;
if (!this.databases[db]) {
this.databases[db] = this.r.branch(this.r.dbList().contains(db), true, this.r.dbCreate(db)).run();
}
return this.databases[db];
}
}, {
key: 'waitForTable',
value: function waitForTable(table, options) {
var _this = this;
options = options || {};
var db = options.db || this.defaults.db;
return this.waitForDb(options).then(function () {
_this.tables[db] = _this.tables[db] || {};
if (!_this.tables[db][table]) {
_this.tables[db][table] = _this.r.branch(_this.r.db(db).tableList().contains(table), true, _this.r.db(db).tableCreate(table)).run();
}
return _this.tables[db][table];
});
}
}, {
key: 'waitForIndex',
value: function waitForIndex(table, index, options) {
var _this2 = this;
/**
* Destroy the record with the given primary key.
*
* @name RethinkDBAdapter#destroy
* @method
* @param {Object} Resource The Resource.
* @param {(string|number)} id Primary key of the record to destroy.
* @param {Object} [opts] Configuration options.
* @return {Promise}
*/
destroy: function destroy(Resource, id, opts) {
var self = this;
opts || (opts = {});
options = options || {};
var db = options.db || this.defaults.db;
return this.waitForDb(options).then(function () {
return _this2.waitForTable(table, options);
}).then(function () {
_this2.indices[db] = _this2.indices[db] || {};
_this2.indices[db][table] = _this2.indices[db][table] || {};
if (!_this2.tables[db][table][index]) {
_this2.tables[db][table][index] = _this2.r.branch(_this2.r.db(db).table(table).indexList().contains(index), true, _this2.r.db(db).table(table).indexCreate(index)).run().then(function () {
return _this2.r.db(db).table(table).indexWait(index).run();
});
}
return _this2.tables[db][table][index];
});
}
}, {
key: 'find',
value: function find(resourceConfig, id, options) {
var _this3 = this;
return self.waitForTable(Resource.table || underscore(Resource.name), opts).then(function () {
return self.selectTable(Resource, opts).get(id).delete().run();
}).then(function () {
return undefined;
});
},
var newModels = {};
var models = {};
var merge = {};
options = options || {};
var table = resourceConfig.table || underscore(resourceConfig.name);
var tasks = [this.waitForTable(table, options)];
forEach(resourceConfig.relationList, function (def) {
var relationName = def.relation;
var relationDef = resourceConfig.getResource(relationName);
if (!relationDef) {
throw new JSData.DSErrors.NER(relationName);
} else if (!options['with'] || !contains(options['with'], relationName)) {
return;
}
if (def.foreignKey) {
tasks.push(_this3.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, options));
} else if (def.localKey) {
tasks.push(_this3.waitForIndex(resourceConfig.table || underscore(resourceConfig.name), def.localKey, options));
}
});
return DSUtils.Promise.all(tasks).then(function () {
return _this3.r['do'](_this3.r.table(table).get(id), function (doc) {
forEach(resourceConfig.relationList, function (def) {
var relationName = def.relation;
models[relationName] = resourceConfig.getResource(relationName);
if (!options['with'] || !contains(options['with'], relationName)) {
return;
}
if (!models[relationName]) {
throw new JSData.DSErrors.NER(relationName);
}
var localKey = def.localKey;
var localField = def.localField;
var foreignKey = def.foreignKey;
if (def.type === 'belongsTo') {
merge[localField] = _this3.r.table(models[relationName].table || underscore(models[relationName].name)).get(doc(localKey)['default'](''));
newModels[localField] = {
modelName: relationName,
relation: 'belongsTo'
};
} else if (def.type === 'hasMany') {
merge[localField] = _this3.r.table(models[relationName].table || underscore(models[relationName].name)).getAll(id, { index: foreignKey }).coerceTo('ARRAY');
newModels[localField] = {
modelName: relationName,
relation: 'hasMany'
};
} else if (def.type === 'hasOne') {
merge[localField] = _this3.r.table(models[relationName].table || underscore(models[relationName].name));
/**
* Destroy the records that match the selection query.
*
* @name RethinkDBAdapter#destroyAll
* @method
* @param {Object} Resource the Resource.
* @param {Object} [query] Selection query.
* @param {Object} [opts] Configuration options.
* @return {Promise}
*/
destroyAll: function destroyAll(Resource, query, opts) {
var self = this;
query || (query = {});
opts || (opts = {});
if (localKey) {
merge[localField] = merge[localField].get(localKey);
} else {
merge[localField] = merge[localField].getAll(id, { index: foreignKey }).coerceTo('ARRAY');
}
return self.waitForTable(Resource.table || underscore(Resource.name), opts).then(function () {
return self.filterSequence(self.selectTable(Resource, opts), query).delete().run();
}).then(function () {
return undefined;
});
},
newModels[localField] = {
modelName: relationName,
relation: 'hasOne'
};
}
});
if (!isEmpty(merge)) {
return doc.merge(merge);
}
return doc;
}).run();
}).then(function (item) {
if (!item) {
return DSUtils.Promise.reject(new Error('Not Found!'));
} else {
forOwn(item, function (localValue, localKey) {
if (localKey in newModels) {
if (isObject(localValue)) {
item[localKey] = item[localKey];
} else if (isArray(localValue)) {
if (newModels[localKey].relation === 'hasOne' && localValue.length) {
item[localKey] = localValue[0];
} else {
item[localKey] = localValue;
}
}
}
});
return item;
}
});
}
}, {
key: 'findAll',
value: function findAll(resourceConfig, params, options) {
var _this4 = this;
/**
* TODO
*
* There may be reasons why you may want to override this method, like when
* the id of the parent doesn't exactly match up to the key on the child.
*
* @name RethinkDBAdapter#makeHasManyForeignKey
* @method
* @return {*}
*/
makeHasManyForeignKey: function makeHasManyForeignKey(Resource, def, record) {
return DSUtils.get(record, Resource.idAttribute);
},
options = options || {};
var table = resourceConfig.table || underscore(resourceConfig.name);
var tasks = [this.waitForTable(table, options)];
var models = {};
var merge = {};
var newModels = {};
forEach(resourceConfig.relationList, function (def) {
var relationName = def.relation;
var relationDef = resourceConfig.getResource(relationName);
if (!relationDef) {
throw new JSData.DSErrors.NER(relationName);
} else if (!options['with'] || !contains(options['with'], relationName)) {
return;
}
if (def.foreignKey) {
tasks.push(_this4.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, options));
} else if (def.localKey) {
tasks.push(_this4.waitForIndex(resourceConfig.table || underscore(resourceConfig.name), def.localKey, options));
}
});
return DSUtils.Promise.all(tasks).then(function () {
var query = _this4.filterSequence(_this4.selectTable(resourceConfig, options), params);
if (options['with'] && options['with'].length) {
query = query.map(function (doc) {
var id = doc(resourceConfig.idAttribute);
forEach(resourceConfig.relationList, function (def) {
var relationName = def.relation;
models[relationName] = resourceConfig.getResource(relationName);
if (!options['with'] || !contains(options['with'], relationName)) {
return;
}
if (!models[relationName]) {
throw new JSData.DSErrors.NER(relationName);
}
var localKey = def.localKey;
var localField = def.localField;
var foreignKey = def.foreignKey;
if (def.type === 'belongsTo') {
merge[localField] = _this4.r.table(models[relationName].table || underscore(models[relationName].name)).get(doc(localKey)['default'](''));
newModels[localField] = {
modelName: relationName,
relation: 'belongsTo'
};
} else if (def.type === 'hasMany') {
merge[localField] = _this4.r.table(models[relationName].table || underscore(models[relationName].name)).getAll(id, { index: foreignKey }).coerceTo('ARRAY');
newModels[localField] = {
modelName: relationName,
relation: 'hasMany'
};
} else if (def.type === 'hasOne') {
merge[localField] = _this4.r.table(models[relationName].table || underscore(models[relationName].name));
/**
* TODO
*
* @name RethinkDBAdapter#loadHasMany
* @method
* @return {Promise}
*/
loadHasMany: function loadHasMany(Resource, def, records, __options) {
var self = this;
var singular = false;
if (localKey) {
merge[localField] = merge[localField].get(localKey);
} else {
merge[localField] = merge[localField].getAll(id, { index: foreignKey }).coerceTo('ARRAY');
}
if (DSUtils.isObject(records) && !DSUtils.isArray(records)) {
singular = true;
records = [records];
}
var IDs = records.map(function (record) {
return self.makeHasManyForeignKey(Resource, def, record);
});
var query = {};
var criteria = query[def.foreignKey] = {};
if (singular) {
// more efficient query when we only have one record
criteria['=='] = IDs[0];
} else {
criteria['in'] = IDs.filter(function (id) {
return id;
});
}
return self.findAll(Resource.getResource(def.relation), query, __options).then(function (relatedItems) {
records.forEach(function (record) {
var attached = [];
// avoid unneccesary iteration when we only have one record
if (singular) {
attached = relatedItems;
} else {
relatedItems.forEach(function (relatedItem) {
if (DSUtils.get(relatedItem, def.foreignKey) === record[Resource.idAttribute]) {
attached.push(relatedItem);
}
});
}
DSUtils.set(record, def.localField, attached);
});
});
},
newModels[localField] = {
modelName: relationName,
relation: 'hasOne'
};
}
});
if (!isEmpty(merge)) {
return doc.merge(merge);
}
return doc;
});
}
return query.run();
});
}
}, {
key: 'create',
value: function create(resourceConfig, attrs, options) {
var _this5 = this;
/**
* TODO
*
* @name RethinkDBAdapter#loadHasOne
* @method
* @return {Promise}
*/
loadHasOne: function loadHasOne(Resource, def, records, __options) {
if (DSUtils.isObject(records) && !DSUtils.isArray(records)) {
records = [records];
}
return this.loadHasMany(Resource, def, records, __options).then(function () {
records.forEach(function (record) {
var relatedData = DSUtils.get(record, def.localField);
if (DSUtils.isArray(relatedData) && relatedData.length) {
DSUtils.set(record, def.localField, relatedData[0]);
}
});
});
},
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
options = options || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this5.r.db(options.db || _this5.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
_this5._handleErrors(cursor);
return cursor.changes[0].new_val;
});
}
}, {
key: 'update',
value: function update(resourceConfig, id, attrs, options) {
var _this6 = this;
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
options = options || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this6.r.db(options.db || _this6.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).update(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
_this6._handleErrors(cursor);
if (cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {
return cursor.changes[0].new_val;
} else {
return _this6.selectTable(resourceConfig, options).get(id).run();
}
});
}
}, {
key: 'updateAll',
value: function updateAll(resourceConfig, attrs, params, options) {
var _this7 = this;
/**
* TODO
*
* @name RethinkDBAdapter#makeBelongsToForeignKey
* @method
* @return {*}
*/
makeBelongsToForeignKey: function makeBelongsToForeignKey(Resource, def, record) {
return DSUtils.get(record, def.localKey);
},
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
options = options || {};
params = params || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this7.filterSequence(_this7.selectTable(resourceConfig, options), params).update(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
_this7._handleErrors(cursor);
if (cursor && cursor.changes && cursor.changes.length) {
var _ret = (function () {
var items = [];
cursor.changes.forEach(function (change) {
return items.push(change.new_val);
});
return {
v: items
};
})();
if (typeof _ret === 'object') return _ret.v;
} else {
return _this7.filterSequence(_this7.selectTable(resourceConfig, options), params).run();
}
});
}
}, {
key: 'destroy',
value: function destroy(resourceConfig, id, options) {
var _this8 = this;
/**
* TODO
*
* @name RethinkDBAdapter#loadBelongsTo
* @method
* @return {Promise}
*/
loadBelongsTo: function loadBelongsTo(Resource, def, records, __options) {
var self = this;
var relationDef = Resource.getResource(def.relation);
options = options || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this8.r.db(options.db || _this8.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id)['delete']().run();
}).then(function () {
return undefined;
});
}
}, {
key: 'destroyAll',
value: function destroyAll(resourceConfig, params, options) {
var _this9 = this;
if (DSUtils.isObject(records) && !DSUtils.isArray(records)) {
var _ret = function () {
var record = records;
return {
v: self.find(relationDef, self.makeBelongsToForeignKey(Resource, def, record), __options).then(function (relatedItem) {
DSUtils.set(record, def.localField, relatedItem);
})
};
}();
options = options || {};
params = params || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this9.filterSequence(_this9.selectTable(resourceConfig, options), params)['delete']().run();
}).then(function () {
return undefined;
});
}
}, {
key: '_handleErrors',
value: function _handleErrors(cursor) {
if (cursor && cursor.errors > 0) {
if (cursor.first_error) {
throw new Error(cursor.first_error);
}
throw new Error('Unknown RethinkDB Error');
}
}
}]);
if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v;
} else {
var _keys = records.map(function (record) {
return self.makeBelongsToForeignKey(Resource, def, record);
}).filter(function (key) {
return key;
});
return self.findAll(relationDef, {
where: babelHelpers.defineProperty({}, relationDef.idAttribute, {
'in': _keys
})
}, __options).then(function (relatedItems) {
records.forEach(function (record) {
relatedItems.forEach(function (relatedItem) {
if (relatedItem[relationDef.idAttribute] === record[def.localKey]) {
DSUtils.set(record, def.localField, relatedItem);
}
});
});
});
}
},
return DSRethinkDBAdapter;
})();
module.exports = DSRethinkDBAdapter;
/**
* Retrieve the record with the given primary key.
*
* @name RethinkDBAdapter#find
* @method
* @param {Object} Resource The Resource.
* @param {(string|number)} id Primary key of the record to retrieve.
* @param {Object} [opts] Configuration options.
* @param {string[]} [opts.with=[]] TODO
* @return {Promise}
*/
find: function find(Resource, id, opts) {
var self = this;
opts || (opts = {});
opts.with || (opts.with = []);
/***/ },
/* 1 */
/***/ function(module, exports) {
var instance = undefined;
var table = Resource.table || underscore(Resource.name);
var relationList = Resource.relationList || [];
var tasks = [self.waitForTable(table, opts)];
module.exports = require("rethinkdbdash");
relationList.forEach(function (def) {
var relationName = def.relation;
var relationDef = Resource.getResource(relationName);
if (!relationDef) {
throw new JSData.DSErrors.NER(relationName);
} else if (!opts.with || !contains(opts.with, relationName)) {
return;
}
if (def.foreignKey) {
tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts));
} else if (def.localKey) {
tasks.push(self.waitForIndex(Resource.table || underscore(Resource.name), def.localKey, opts));
}
});
return DSUtils.Promise.all(tasks).then(function () {
return self.selectTable(Resource, opts).get(id).run();
}).then(function (_instance) {
if (!_instance) {
throw new Error('Not Found!');
}
instance = _instance;
var tasks = [];
/***/ },
/* 2 */
/***/ function(module, exports) {
relationList.forEach(function (def) {
var relationName = def.relation;
var relationDef = Resource.getResource(relationName);
var containedName = null;
if (opts.with.indexOf(relationName) !== -1) {
containedName = relationName;
} else if (opts.with.indexOf(def.localField) !== -1) {
containedName = def.localField;
}
if (containedName) {
(function () {
var __options = DSUtils.deepMixIn({}, opts.orig ? opts.orig() : opts);
__options.with = opts.with.slice();
__options = DSUtils._(relationDef, __options);
DSUtils.remove(__options.with, containedName);
__options.with.forEach(function (relation, i) {
if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {
__options.with[i] = relation.substr(containedName.length + 1);
} else {
__options.with[i] = '';
}
});
module.exports = require("js-data");
var task = undefined;
/***/ },
/* 3 */
/***/ function(module, exports) {
if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {
if (def.type === 'hasOne') {
task = self.loadHasOne(Resource, def, instance, __options);
} else {
task = self.loadHasMany(Resource, def, instance, __options);
}
} else if (def.type === 'hasMany' && def.localKeys) {
var localKeys = [];
var itemKeys = instance[def.localKeys] || [];
itemKeys = DSUtils.isArray(itemKeys) ? itemKeys : DSUtils.keys(itemKeys);
localKeys = localKeys.concat(itemKeys || []);
task = self.findAll(Resource.getResource(relationName), {
where: babelHelpers.defineProperty({}, relationDef.idAttribute, {
'in': unique(localKeys).filter(function (x) {
return x;
})
})
}, __options).then(function (relatedItems) {
DSUtils.set(instance, def.localField, relatedItems);
return relatedItems;
});
} else if (def.type === 'belongsTo' || def.type === 'hasOne' && def.localKey) {
task = self.loadBelongsTo(Resource, def, instance, __options);
}
module.exports = require("mout/string/underscore");
if (task) {
tasks.push(task);
}
})();
}
});
/***/ }
/******/ ]);
return DSUtils.Promise.all(tasks);
}).then(function () {
return instance;
});
},
/**
* Retrieve the records that match the selection query.
*
* @name RethinkDBAdapter#findAll
* @method
* @param {Object} Resource The Resource.
* @param {Object} query Selection query.
* @param {Object} [opts] Configuration options.
* @param {string[]} [opts.with=[]] TODO
* @return {Promise}
*/
findAll: function findAll(Resource, query, opts) {
var self = this;
opts || (opts = {});
opts.with || (opts.with = []);
var items = null;
var table = Resource.table || underscore(Resource.name);
var relationList = Resource.relationList || [];
var tasks = [self.waitForTable(table, opts)];
relationList.forEach(function (def) {
var relationName = def.relation;
var relationDef = Resource.getResource(relationName);
if (!relationDef) {
throw new JSData.DSErrors.NER(relationName);
} else if (!opts.with || !contains(opts.with, relationName)) {
return;
}
if (def.foreignKey) {
tasks.push(self.waitForIndex(relationDef.table || underscore(relationDef.name), def.foreignKey, opts));
} else if (def.localKey) {
tasks.push(self.waitForIndex(Resource.table || underscore(Resource.name), def.localKey, opts));
}
});
return DSUtils.Promise.all(tasks).then(function () {
return self.filterSequence(self.selectTable(Resource, opts), query).run();
}).then(function (_items) {
items = _items;
var tasks = [];
var relationList = Resource.relationList || [];
relationList.forEach(function (def) {
var relationName = def.relation;
var relationDef = Resource.getResource(relationName);
var containedName = null;
if (opts.with.indexOf(relationName) !== -1) {
containedName = relationName;
} else if (opts.with.indexOf(def.localField) !== -1) {
containedName = def.localField;
}
if (containedName) {
(function () {
var __options = DSUtils.deepMixIn({}, opts.orig ? opts.orig() : opts);
__options.with = opts.with.slice();
__options = DSUtils._(relationDef, __options);
DSUtils.remove(__options.with, containedName);
__options.with.forEach(function (relation, i) {
if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {
__options.with[i] = relation.substr(containedName.length + 1);
} else {
__options.with[i] = '';
}
});
var task = undefined;
if (def.foreignKey && (def.type === 'hasOne' || def.type === 'hasMany')) {
if (def.type === 'hasMany') {
task = self.loadHasMany(Resource, def, items, __options);
} else {
task = self.loadHasOne(Resource, def, items, __options);
}
} else if (def.type === 'hasMany' && def.localKeys) {
(function () {
var localKeys = [];
items.forEach(function (item) {
var itemKeys = item[def.localKeys] || [];
itemKeys = DSUtils.isArray(itemKeys) ? itemKeys : Object.keys(itemKeys);
localKeys = localKeys.concat(itemKeys || []);
});
task = self.findAll(Resource.getResource(relationName), {
where: babelHelpers.defineProperty({}, relationDef.idAttribute, {
'in': unique(localKeys).filter(function (x) {
return x;
})
})
}, __options).then(function (relatedItems) {
items.forEach(function (item) {
var attached = [];
var itemKeys = item[def.localKeys] || [];
itemKeys = DSUtils.isArray(itemKeys) ? itemKeys : DSUtils.keys(itemKeys);
relatedItems.forEach(function (relatedItem) {
if (itemKeys && itemKeys.indexOf(relatedItem[relationDef.idAttribute]) !== -1) {
attached.push(relatedItem);
}
});
DSUtils.set(item, def.localField, attached);
});
return relatedItems;
});
})();
} else if (def.type === 'belongsTo' || def.type === 'hasOne' && def.localKey) {
task = self.loadBelongsTo(Resource, def, items, __options);
}
if (task) {
tasks.push(task);
}
})();
}
});
return DSUtils.Promise.all(tasks);
}).then(function () {
return items;
});
},
/**
* Apply the given update to the record with the specified primary key.
*
* @name RethinkDBAdapter#update
* @method
* @param {Object} Resource The Resource.
* @param {(string|number)} id The primary key of the record to be updated.
* @param {Object} props The update to apply to the record.
* @param {Object} [opts] Configuration options.
* @return {Promise}
*/
update: function update(resourceConfig, id, attrs, options) {
var _this = this;
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
options = options || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this.r.db(options.db || _this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).update(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
_this._handleErrors(cursor);
if (cursor.changes && cursor.changes.length && cursor.changes[0].new_val) {
return cursor.changes[0].new_val;
} else {
return _this.selectTable(resourceConfig, options).get(id).run();
}
});
},
/**
* Apply the given update to all records that match the selection query.
*
* @name RethinkDBAdapter#updateAll
* @method
* @param {Object} Resource The Resource.
* @param {Object} props The update to apply to the selected records.
* @param {Object} [query] Selection query.
* @param {Object} [opts] Configuration options.
* @return {Promise}
*/
updateAll: function updateAll(resourceConfig, attrs, params, options) {
var _this2 = this;
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
options = options || {};
params = params || {};
return this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return _this2.filterSequence(_this2.selectTable(resourceConfig, options), params).update(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
_this2._handleErrors(cursor);
if (cursor && cursor.changes && cursor.changes.length) {
var _ret5 = function () {
var items = [];
cursor.changes.forEach(function (change) {
return items.push(change.new_val);
});
return {
v: items
};
}();
if ((typeof _ret5 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret5)) === "object") return _ret5.v;
} else {
return _this2.filterSequence(_this2.selectTable(resourceConfig, options), params).run();
}
});
},
waitForTable: function waitForTable(table, options) {
var _this3 = this;
options = options || {};
var db = options.db || this.defaults.db;
return this.waitForDb(options).then(function () {
_this3.tables[db] = _this3.tables[db] || {};
if (!_this3.tables[db][table]) {
_this3.tables[db][table] = _this3.r.branch(_this3.r.db(db).tableList().contains(table), true, _this3.r.db(db).tableCreate(table)).run();
}
return _this3.tables[db][table];
});
},
waitForIndex: function waitForIndex(table, index, options) {
var _this4 = this;
options = options || {};
var db = options.db || this.defaults.db;
return this.waitForDb(options).then(function () {
return _this4.waitForTable(table, options);
}).then(function () {
_this4.indices[db] = _this4.indices[db] || {};
_this4.indices[db][table] = _this4.indices[db][table] || {};
if (!_this4.tables[db][table][index]) {
_this4.tables[db][table][index] = _this4.r.branch(_this4.r.db(db).table(table).indexList().contains(index), true, _this4.r.db(db).table(table).indexCreate(index)).run().then(function () {
return _this4.r.db(db).table(table).indexWait(index).run();
});
}
return _this4.tables[db][table][index];
});
}
});
module.exports = RethinkDBAdapter;
//# sourceMappingURL=js-data-rethinkdb.js.map
{
"name": "js-data-rethinkdb",
"description": "RethinkDB adapter for js-data.",
"version": "2.1.0",
"homepage": "http://www.js-data.io/docs/dsrethinkdbadapter",
"version": "2.2.0",
"homepage": "https://github.com/js-data/js-data-rethinkdb",
"repository": {

@@ -10,6 +10,3 @@ "type": "git",

},
"author": {
"name": "Jason Dobry",
"email": "jason.dobry@gmail.com"
},
"author": "js-data-rethinkdb project authors",
"license": "MIT",

@@ -26,35 +23,53 @@ "main": "./dist/js-data-rethinkdb.js",

],
"devDependencies": {
"babel-core": "5.8.25",
"babel-eslint": "4.1.3",
"babel-loader": "5.3.2",
"bluebird": "2.10.2",
"chai": "3.3.0",
"co": "4.6.0",
"co-mocha": "1.1.2",
"codacy-coverage": "1.1.3",
"coveralls": "2.11.4",
"istanbul": "0.4.0",
"mocha": "2.3.3",
"standard": "5.3.1",
"webpack": "1.12.2"
"standard": {
"parser": "babel-eslint",
"globals": [
"describe",
"it",
"sinon",
"assert",
"before",
"after",
"beforeEach",
"afterEach"
]
},
"scripts": {
"lint": "standard src/index.js",
"build": "webpack --config webpack.config.js --colors",
"mocha": "mocha --timeout 20000 --reporter dot mocha.start.js test/*.spec.js",
"cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- --timeout 20000 --reporter dot mocha.start.js test/*.spec.js",
"test": "npm run lint && npm run build && npm run cover",
"doc": "jsdoc -c conf.json src && node scripts/cleanup.js",
"bundle": "rollup -c rollup.config.js -f cjs -o dist/js-data-rethinkdb.js -m dist/js-data-rethinkdb.js.map src/index.js",
"lint": "standard src/index.js mocha.start.js test/**/*.js",
"mocha": "mocha -t 20000 -R dot mocha.start.js test/**/*.js",
"cover": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- -t 20000 -R dot mocha.start.js test/**/*.js",
"test": "npm run lint && npm run bundle && npm run cover",
"release": "npm test && npm run doc && node scripts/authors.js",
"ci": "npm run test && cat coverage/lcov.info | coveralls || true && cat ./coverage/lcov.info | codacy-coverage || true"
},
"standard": {
"parser": "babel-eslint"
},
"dependencies": {
"mout": "0.11.0"
"mout": "0.11.1"
},
"peerDependencies": {
"js-data": ">=2.0.0",
"js-data": ">=2.0.0 <3",
"rethinkdbdash": ">=1.15.0"
},
"devDependencies": {
"babel-core": "6.5.2",
"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",
"codacy-coverage": "1.1.3",
"coveralls": "2.11.6",
"ink-docstrap": "1.1.2",
"istanbul": "0.4.2",
"js-data-adapter-tests": "1.5.0",
"jsdoc": "3.4.0",
"mocha": "2.4.5",
"rollup": "0.25.4",
"rollup-plugin-babel": "2.4.0",
"source-map-support": "0.4.0",
"standard": "6.0.7"
}
}

105

README.md

@@ -1,90 +0,79 @@

<img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" />
<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" />
## js-data-rethinkdb [![Slack Status][sl_b]][sl_l] [![npm version][npm_b]][npm_l] [![Circle CI][circle_b]][circle_l] [![npm downloads][dn_b]][dn_l] [![Coverage Status][cov_b]][cov_l] [![Codacy][cod_b]][cod_l]
# js-data-rethinkdb
[![Slack Status][sl_b]][sl_l]
[![npm version][npm_b]][npm_l]
[![Circle CI][circle_b]][circle_l]
[![npm downloads][dn_b]][dn_l]
[![Coverage Status][cov_b]][cov_l]
[![Codacy][cod_b]][cod_l]
RethinkDB adapter for [js-data](http://www.js-data.io/).
### API Documentation
[DSRethinkDBAdapter](http://www.js-data.io/docs/dsrethinkdbadapter)
To get started, visit __[http://js-data.io](http://www.js-data.io)__.
### Example App
[js-data-examples/server/rethinkdb](https://github.com/js-data/js-data-examples/tree/master/server/rethinkdb)
## Table of contents
### Quick Start
`npm install --save js-data js-data-rethinkdb rethinkdbdash`.
* [Quick start](#quick-start)
* [Example App](#example-app)
* [Guides and Tutorials](#guides-and-tutorials)
* [API Reference Docs](#api-reference-docs)
* [Community](#community)
* [Support](#support)
* [Contributing](#contributing)
* [License](#license)
## Quick Start
`npm install --save js-data js-data-rethinkdb`.
```js
var JSData = require('js-data');
var DSRethinkDBAdapter = require('js-data-rethinkdb');
var RethinkDBAdapter = require('js-data-rethinkdb');
var store = new JSData.DS();
var adapter = new RethinkDBAdapter();
// "r" will be available at adapter.r
var adapter = new DSRethinkDBAdapter();
// "store" will now use the RethinkDB adapter for all async operations
store.registerAdapter('rethinkdb', adapter, { default: true });
// "store" will now use the RethinkDB adapter for all async operations
var User = store.defineResource({
name: 'user'
});
```
### Changelog
[CHANGELOG.md](https://github.com/js-data/js-data-rethinkdb/blob/master/CHANGELOG.md)
## Example App
### Community
- [Slack Channel](http://slack.js-data.io/) - Better than IRC!
- [Announcements](http://www.js-data.io/blog)
- [Mailing List](https://groups.io/org/groupsio/jsdata) - Ask your questions!
- [Issues](https://github.com/js-data/js-data-rethinkdb/issues) - Found a bug? Feature request? Submit an issue!
- [GitHub](https://github.com/js-data/js-data-rethinkdb) - View the source code for js-data.
- [Contributing Guide](https://github.com/js-data/js-data-rethinkdb/blob/master/CONTRIBUTING.md)
[js-data-examples/server/rethinkdb](https://github.com/js-data/js-data-examples/tree/master/server/rethinkdb)
### Contributing
## Guides and Tutorials
First, support is handled via the [Slack Channel](http://slack.js-data.io/) and the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
[Get started at http://js-data.io](http://js-data.io)
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
## API Reference Docs
- good - Your versions of js-data, js-data-rethinkdb, etc., relevant console logs/error, code examples that revealed the issue
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
[Visit http://api.js-data.io](http://api.js-data.io).
[Github Issues](https://github.com/js-data/js-data-rethinkdb/issues).
## Community
#### Submitting Pull Requests
[Explore the Community](http://js-data.io/docs/community).
1. Contribute to the issue/discussion that is the reason you'll be developing in the first place
1. Fork js-data-rethinkdb
1. `git clone git@github.com:<you>/js-data-rethinkdb.git`
1. `cd js-data-rethinkdb; npm install; bower install;`
1. Write your code, including relevant documentation and tests
1. Run `grunt test` (build and test)
1. Your code will be linted and checked for formatting, the tests will be run
1. The `dist/` folder & files will be generated, do NOT commit `dist/*`! They will be committed when a release is cut.
1. Submit your PR and we'll review!
1. Thanks!
## Support
### License
[Find out how to Get Support](http://js-data.io/docs/support).
The MIT License (MIT)
## Contributing
Copyright (c) 2014-2015 Jason Dobry
[Read the Contributing Guide](http://js-data.io/docs/contributing).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
## License
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The MIT License (MIT)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright (c) 2014-2016 js-data-rethinkdb project authors
* [LICENSE](https://github.com/js-data/js-data-rethinkdb/blob/master/LICENSE)
* [AUTHORS](https://github.com/js-data/js-data-rethinkdb/blob/master/AUTHORS)
* [CONTRIBUTORS](https://github.com/js-data/js-data-rethinkdb/blob/master/CONTRIBUTORS)
[sl_b]: http://slack.js-data.io/badge.svg

@@ -91,0 +80,0 @@ [sl_l]: http://slack.js-data.io

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc