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

Docs, Issues

Yes

Yes

bower versionbower version

npm versionnpm version

http

Docs, Issues

Yes

No

bower versionbower version

npm versionnpm version

levelup

Docs, Issues

No

Yes

n/a

npm versionnpm version

localforage

Docs, Issues

Yes

No

bower versionbower version

npm versionnpm version

localstorage

Docs, Issues

Yes

No

bower versionbower version

npm versionnpm version

mongodb

Docs, Issues

No

Yes

n/a

npm versionnpm version

nedb

Docs, Issues

No

Yes

n/a

npm versionnpm version

redis

Docs, Issues

No

Yes

n/a

npm versionnpm version

rethinkdb

Docs, Issues

No

Yes

n/a

npm versionnpm version

sql

Docs, Issues

No

Yes

n/a

npm versionnpm 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

Updated less than a minute ago

Adapters


How the data store communicates with persistence layers

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.