Database agnostic ODM
Install
$ npm install --save lawson nosqwal-memory
Setup
orm.js
;; const noSqwalInstance = ; const collection = defineCollection;
models/user.js
; 'user' username: 'string' email: 'string' password: 'string';
Usage
; /* create */user/* get *//* update */;
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