js-data

Respect Your Data

Give your data the treatment it deserves with a framework-agnostic, datastore-agnostic JavaScript ORM built for ease of use and peace of mind. Works in Node.js and in the Browser.

Get Started

Adapters

How the data store communicates with persistence layers

The data store is an organized in-memory cache and has no knowledge of persistence layers. Adapters are used by the data store to communicate with persistence layers. When you use an async method of the data store, some of the work will most likely be delegated to an adapter.

Target
Links
Browser Support?
Node.js Support?
Bower
NPM

firebase

Yes

Yes

bower version

npm version

http

Yes

No

bower version

npm version

levelup

No

Yes

n/a

npm version

localforage

Yes

No

bower version

npm version

localstorage

Yes

No

bower version

npm version

mongodb

No

Yes

n/a

npm version

nedb

No

Yes

n/a

npm version

redis

No

Yes

n/a

npm version

rethinkdb

No

Yes

n/a

npm version

sql

No

Yes

n/a

npm version

Custom Adapters

Implementing your own adapter is easy. You can view the source code of the existing adapters for examples.

Here is a pseudo example:

function MyCustomAdapter() {
  
}

// All of the methods shown here must return a promise

// "definition" is a resource defintion that would
// be returned by DS#defineResource

// "options" would be the options argument that
// was passed into the DS method that is calling
// the adapter method

MyCustomAdapter.prototype.create = function (definition, attrs, options) {
  // Must return a promise that resolves with the created item
};

MyCustomAdapter.prototype.find = function (definition, id, options) {
  // Must return a promise that resolves with the found item
};

MyCustomAdapter.prototype.findAll = function (definition, params, options) {
  // Must return a promise that resolves with the found items
};

MyCustomAdapter.prototype.update = function (definition, id, attrs, options) {
  // Must return a promise that resolves with the updated item
};

MyCustomAdapter.prototype.updateAll = function (definition, attrs, params, options) {
  // Must return a promise that resolves with the updated items
};

MyCustomAdapter.prototype.destroy = function (definition, id, options) {
  // Must return a promise 
};

MyCustomAdapter.prototype.destroyAll = function (definition, params, options) {
  // Must return a promise 
};

Then use it:

var store = new JSData.DS();
store.registerAdapter('mca', new MyCustomAdapter(), { default: true });

// the data store will now use your custom adapter by default

Adapters

How the data store communicates with persistence layers