level-model

A higher-level module for creating content models using levelup as db and is-my-json-valid for validation.

level-model

A higher-level module for creating content models using levelup as db and is-my-json-valid for validation.

var level = require('level')
var Model = require('level-model')
var inherits = require('util').inherits
var db = level('db')
 
function Posts (db, opts) {
  Model.call(this, db, opts)
}
 
inherits(Posts, Model)
 
var posts = new Posts(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)
})
var Model = require('level-model')
var inherits = require('util').inherits
 
function Posts (db, options) {
  Model.call(this, db, options)
}
 
inherits(Posts, Model)

Options:

{
  modelName: '',
  indexKeys: [],
  schema: {
    title: "Example",
    type: "object",
    properties: {},
    required: []
  }
}

Or:

{
  modelName: 'Example',
  indexKeys: [],
  properties: {},
  required: []
}

The options object can accept anything that json-schema accepts.

MIT