A higher-level module for creating content models using leveldb.
level-model is a wrapper around leveldb that provides validation and indexing.
Validation is provided using the is-my-json-valid module.
Indexing is achieved using the level-simple-indexes module, which in turn relies on level-indexer.
npm install --save level-model
var level = require('level')
var Model = require('level-model')
var db = level('db')
var posts = Model(db, {
modelName: 'example',
indexKeys: ['test', 'ok'],
properties: {
title: { type: 'string' },
content: { type: 'string' },
},
required: ['title']
})
var data = {
title: 'first post!',
content: 'this is some text.'
}
posts.create(data, function (err, post) {
console.log(err, post)
})
Contributions are welcome! Please read the contributing guidelines first.
It is important that this project contributes to a friendly, safe, and welcoming environment for all. Read this project's code of conduct
Read about the changes to this project in CHANGELOG.md. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
Options:
{
modelName: 'Example',
indexKeys: [],
properties: {},
required: []
}
The options object can accept anything that json-schema accepts.
Add beforeCreate
and beforeUpdate
methods to options.hooks
to format data before it is saved to the db:
var posts = Model(db, {
modelName: 'posts',
hooks: {
beforeCreate: function (data) {
data.slug = slugify(data.title)
return data
},
beforeUpdate: function (data) {
return data
}
}
})
- issues – Please open issues in the issues queue
- twitter – Have a question? @sethdvincent
- email – Need in-depth support via paid contract? Send an email to sethvincent@gmail.com