Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lawson

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lawson

Database agnostic ODM

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

lawson Build Status

Database agnostic ODM

Install

$ npm install --save lawson nosqwal-memory

Setup

orm.js

import nosqwal from 'nosqwal-memory';
import lawson from 'lawson';

const noSqwalInstance = noSqwal();

export const collection = lawson(noSqwalInstance).defineCollection;

models/user.js

import {collection} from '../orm';

export default collection('user', {
    username: 'string',
    email: 'string',
    password: 'string'
});

Usage

import user from './models/user';

/*   create   */
user.create({
    username: 'test',
    email: 'test@test.com',
    password: 'secret'
})
/*   get   */
.then(createdUser => {
    return user.get(createdUser.id);
})
/*   update   */
.then(newUser => {
    newUser.username = 'bobby';

    return user.update(newUser.id, newUser);
})
.then(updatedUser => {
    console.log('user updated');
})
.then(() => {
    return user.query({
        where: {
            username: 'bobby'
        }
    });
})
.then(users => {
    console.log(user.length);
    // => 1

    return user.delete(users[0].id);
})
.catch(e => {
    console.warn(e);
});

API

lawsonInstance = lawson(noSqwalInstance)

Create a new instance of lawson

noSqwalInstance

Type: Nosqwal instance
required

collection = lawsonInstance.defineCollection(collectionName, modelDefinition)

Define a new collection

collectionName

Type: string
required

the name of the collection

modelDefinition

Type: object required

The schema of the document, see its definition here

collection.get(documentId)

Returns a Promise, that resolve to the requested document

documentId

Type: string
required

collection.update(document)

Returns a Promise, that resolve when the document is updated

document

Type: object required

the new version of the document that will be updated

document.id

Type: string required

the id of the document to update

collection.create(document)

Returns a Promise, that resolve to the created document

document

Type: object required

The document that will be created

collection.delete(documentId)

Returns a Promise when the document is deleted

documentId

Type: string required

The id of the document that will be deleted

collection.query(options)

Returns a Promise, that resolve to all the documents

options.where

Type: object

Used to filter out results of the query

options.limit

Type: number

The number of documents to return

options.offset

Type: number
default: 0

The number of documents to skip

collection.first(where)

Like query(), but return a promise for only one document

where

Type: object

Used to filter out results of the query

collection.single(where)

Like first(), but throws an error if there is more that one document that matches the where clause

where

Type: object

Used to filter out results of the query

License

MIT © Thomas Sileghem

Keywords

FAQs

Package last updated on 06 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc