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

yet another couchbase orm

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

lawson Build Status

Yet another Couchbase Orm

Install

$ npm install --save lawson

Setup

orm.js

import couchbase from 'couchbase';
import lawson from 'lawson';

const cluster = new couchbase.Cluster();
const bucket = cluster.openBucket();

const lawsonInstance = lawson(bucket);

export const model = lawsonInstance.defineModel;

models/user.js

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

export const default = model('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(couchbaseBucket)

Create a new instance of lawson

couchbaseBucket

Type: Bucket
required

The bucket the library is storing documents

model = lawsonInstance.defineModel(modelName, modelDefinition)

Define a new model

modelName

Type: string
required

the type of the document

modelDefinition

Type: object required

the structure the document is following

model.get(documentId)

Returns a Promise, that resolve to the requested document

documentId

Type: string
required

model.update(documentId, document)

Returns a Promise, that resolve when the document is updated

documentId

Type: string required

the id of the document to update

document

Type: object required

the new version of the document that will be updated

model.create(document)

Returns a Promise, that resolve to the created document

document

Type: object required

The document that will be created

model.delete(documentId)

Returns a Promise when the document is deleted

documentId

Type: string required

The id of the document that will be deleted

model.query(options)

Returns a Promise, that resolve to all the documents

options.where

Type: object

Used to filter out results of the query

License

MIT © Thomas Sileghem

Keywords

FAQs

Package last updated on 17 Jan 2016

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