js-data-memory
v0.1.4
Published
In-memory adapter for js-data.
Downloads
7
Readme
js-data-memory
An in-memory adapter for the JSData Node.js ORM. Credits to JDobry.
Installation
npm install --save js-data js-data-memory
Usage
var MemoryAdapter = require('js-data-memory');
/*
* Create an instance of the adapter
*/
var adapter = new MemoryAdapter();
/*
* Register the adapter instance
*/
store.registerAdapter('memory', adapter, { default: true });
JSData Tutorial
Start with the JSData.
License
[The MIT License (MIT)]
Example
var jsData = require('js-data');
var MemoryAdapter = require('js-data-memory');
/*
* Optional
*/
jsData.utils.Promise = require('bluebird');
var adapter = new MemoryAdapter();
var container = new jsData.Container({ mapperDefaults: { } });
container.registerAdapter('memory', adapter, { 'default': true });
container.defineMapper('users');
container
.count('users')
.then(function (data) {
res.send(JSON.stringify(data));
})
.catch(function (error) {
res.send('ERROR<br>' + JSON.stringify(error));
});
container
.create('users',{name: 'name', password: 'password'})
.then(function (data) {
res.send(JSON.stringify(data));
})
.catch(function (error) {
res.send('ERROR<br>' + JSON.stringify(error));
});
container
.findAll('users',{where: { password: { '==': 'password'} } })
.then(function (data) {
res.send(JSON.stringify(data));
})
.catch(function (error) {
res.send('ERROR<br>' + JSON.stringify(error));
});
Contributing
First, look at the issues page to ensure your issue isn't already known. If it's not, you can create a new issue with a detailed description of what happened & how to reproduce the unexpected behavior.
If you decide to take on the challenge of fixing a known (or unknown) issue, you can do so by sending in a pull request from your own fork of the project. Once it has been tested and approved, it will be merged into the master branch of the repository.