npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lawson

v2.0.1

Published

Database agnostic ODM

Downloads

20

Readme

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: '[email protected]',
    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