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

js-data-rethinkdb

Package Overview
Dependencies
Maintainers
1
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 0.2.0 to 1.0.0-alpha.1

5

CHANGELOG.md

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

##### 1.0.0-alpha.1 - 01 November 2014
###### Backwards compatible API changes
- #1 - auto create db and tables if they don't exist
##### 0.2.0 - 03 October 2014

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

14

package.json
{
"name": "js-data-rethinkdb",
"description": "RethinkDB adapter for js-data.",
"version": "0.2.0",
"homepage": "http://www.js-data.io/js-data-rethinkdb",
"version": "1.0.0-alpha.1",
"homepage": "http://www.js-data.io/docs/dsrethinkdbadapter",
"repository": {
"type": "git",
"url": "git://github.com/js-data/js-data-rethinkdb.git"
"url": "https://github.com/js-data/js-data-rethinkdb.git"
},

@@ -36,5 +36,5 @@ "author": {

"grunt-karma-coveralls": "2.5.2",
"grunt-mocha-test": "0.12.1",
"jit-grunt": "0.8.0",
"sinon": "1.10.3",
"grunt-mocha-test": "0.12.2",
"jit-grunt": "0.9.0",
"sinon": "1.11.1",
"time-grunt": "1.0.0"

@@ -46,3 +46,3 @@ },

"dependencies": {
"js-data": "~0.4.x",
"js-data": "~1.0.x",
"mout": "0.10.0",

@@ -49,0 +49,0 @@ "rethinkdbdash": "~1.15.x"

@@ -5,6 +5,6 @@ <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" />

RethinkDB adapter for [js-data](http://www.js-data.io/js-data).
RethinkDB adapter for [js-data](http://www.js-data.io/).
## API Documentation
[DSRethinkDBAdapter](https://github.com/js-data/js-data/wiki/DSRethinkDBAdapter)
[DSRethinkDBAdapter](http://www.js-data.io/docs/dsrethinkdbadapter)

@@ -11,0 +11,0 @@ ## Project Status

@@ -33,5 +33,6 @@ var rethinkdbdash = require('rethinkdbdash');

function filterQuery(resourceConfig, params) {
function filterQuery(resourceConfig, params, options) {
var r = this.r;
params = params || {};
options = options || {};
params.where = params.where || {};

@@ -55,3 +56,3 @@ params.orderBy = params.orderBy || params.sort;

var query = r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name));
var query = r.db(options.db || this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name));
var subQuery;

@@ -136,2 +137,4 @@

this.r = rethinkdbdash(this.defaults);
this.databases = {};
this.tables = {};
}

@@ -141,4 +144,31 @@

dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id) {
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).run().then(function (item) {
dsRethinkDBAdapterPrototype.waitForDb = function waitForDb(options) {
var _this = this;
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];
};
dsRethinkDBAdapterPrototype.waitForTable = 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];
});
};
dsRethinkDBAdapterPrototype.find = function find(resourceConfig, id, options) {
var _this = this;
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).run();
}).then(function (item) {
if (!item) {

@@ -152,8 +182,16 @@ throw new Error('Not Found!');

dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params) {
return filterQuery.call(this, resourceConfig, params).run();
dsRethinkDBAdapterPrototype.findAll = function (resourceConfig, params, options) {
var _this = this;
options = options || {};
return _this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return filterQuery.call(_this, resourceConfig, params, options).run();
});
};
dsRethinkDBAdapterPrototype.create = function (resourceConfig, attrs) {
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs, { returnChanges: true }).run().then(function (cursor) {
dsRethinkDBAdapterPrototype.create = function (resourceConfig, attrs, options) {
var _this = this;
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)).insert(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
return cursor.changes[0].new_val;

@@ -163,4 +201,8 @@ });

dsRethinkDBAdapterPrototype.update = function (resourceConfig, id, attrs) {
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).update(attrs, { returnChanges: true }).run().then(function (cursor) {
dsRethinkDBAdapterPrototype.update = function (resourceConfig, id, attrs, options) {
var _this = this;
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) {
return cursor.changes[0].new_val;

@@ -170,5 +212,9 @@ });

dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params) {
dsRethinkDBAdapterPrototype.updateAll = function (resourceConfig, attrs, params, options) {
var _this = this;
options = options || {};
params = params || {};
return filterQuery.call(this, resourceConfig, params).update(attrs, { returnChanges: true }).run().then(function (cursor) {
return _this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return filterQuery.call(_this, resourceConfig, params, options).update(attrs, { returnChanges: true }).run();
}).then(function (cursor) {
var items = [];

@@ -182,4 +228,8 @@ cursor.changes.forEach(function (change) {

dsRethinkDBAdapterPrototype.destroy = function (resourceConfig, id) {
return this.r.db(this.defaults.db).table(resourceConfig.table || underscore(resourceConfig.name)).get(id).delete().run().then(function () {
dsRethinkDBAdapterPrototype.destroy = function (resourceConfig, id, options) {
var _this = this;
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).delete().run();
}).then(function () {
return undefined;

@@ -189,5 +239,9 @@ });

dsRethinkDBAdapterPrototype.destroyAll = function (resourceConfig, params) {
dsRethinkDBAdapterPrototype.destroyAll = function (resourceConfig, params, options) {
var _this = this;
options = options || {};
params = params || {};
return filterQuery.call(this, resourceConfig, params).delete().run().then(function () {
return _this.waitForTable(resourceConfig.table || underscore(resourceConfig.name), options).then(function () {
return filterQuery.call(_this, resourceConfig, params, options).delete().run();
}).then(function () {
return undefined;

@@ -194,0 +248,0 @@ });

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