js-data-memory

0.1.4 • Public • Published
js-data logo

Codetree

npm Scrutinizer Build Scrutinizer Scrutinizer Coverage npm

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.

/js-data-memory/

    Package Sidebar

    Install

    npm i js-data-memory

    Weekly Downloads

    2

    Version

    0.1.4

    License

    MIT

    Unpacked Size

    63.3 kB

    Total Files

    8

    Last publish

    Collaborators

    • finwo