mastilver / nosqwal

NoSQL Database interface
MIT License
1 stars 0 forks source link

nosqwal Build Status Coverage Status

Low level ODM library

Install

$ npm install --save nosqwal-memory

Adapters

Usage

const nosqwal = require('nosqwal-memory');
const db = nosqwal();

const userCollection = db.defineCollection('user');

userCollection.create({
    username: 'Alice',
    password: '*****'
})
.then(alice => {
    return userCollection.query(
        where: {
            username: {
                $eq: 'Alice'
            }
        },
        limit: 1
    });
})
.then(users => {
    console.log(users[0].username);
    //=> 'Alice'
});

API

const db = nosqwal([options])

options

Type: Object
Default: {}

Options needed to customize your nosqwal instance, they are different for each nosqwal adapters

const collection = db.defineCollection(collectionName)

collectionName

Type: string

Name of the collection

collection.create(document);

Retuns a Promise that resolve to the newly created document The property id is added to that document

document

Type: Object

The document that will be created

collection.get(documentId)

Returns a Promise that resolve to the requested document

documentId

The unique identifier of the document to retrieve

collection.update(document)

Returns a Promise that resolve to the updated document

Type: string

document

The object that will replace the current document stored in the database

document.id

The unique identifier of the document to update

collection.query({ where, orderBy, limit, offset })

Returns a Promise that resolve in an array of the requested document

where

Type: Object

where[key] = whereClause
key

Type: string

Key or path of field to match

Key could also be one of the following for more complex query:

whereClause

Type: object

WhereClause define the where clause for a field. WhereClause can also be the same as where for more complex query.

whereClause[operator] = value

Operator can be:

operator description value type data type
$eq equal to any any
$ne not equal to any any
$gt gretter than string,number,Date string,number,Date
$gte gretter or equal to string,number,Date string,number,Date
$lt lower than string,number,Date string,number,Date
$lte lower or equal to string,number,Date string,number,Date
$contains string/array contains any string, Array
$in is in array Array any

orderBy

Type: array
Default: []

orderBy[][0]

Type: string

Path / key to order

orderBy[][1]

Is ascending

Type: bool
Default: true

limit

Type: number
Default: undefined

How many documents will be returned

offset

Type: number
Default: 0

License

MIT © Thomas Sileghem