3.1.1 • Published 7 years ago

level-model v3.1.1

Weekly downloads
120
License
-
Repository
github
Last release
7 years ago

level-model

A higher-level module for creating content models using leveldb.

npm travis standard conduct

About

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.

Install

npm install --save level-model

Usage

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)
})

Contributing

Contributions are welcome! Please read the contributing guidelines first.

Conduct

It is important that this project contributes to a friendly, safe, and welcoming environment for all. Read this project's code of conduct

Changelog

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.

API

Create a model by calling the function exported from level-model

var posts = Model(db, options)

Options:

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

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

posts.create(data, callback)

posts.get(key, options, callback)

posts.update(key, data, callback)

posts.delete(key, callback)

posts.createReadStream(options)

posts.find(index, options)

Format data before create & update

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
    }
  }
})

Events

example.on('create', function (model) {})

example.on('update', function (model) {})

example.on('delete', function () {})

Contact

  • 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

License

ISC

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.5.3

10 years ago

1.5.2

10 years ago

1.5.1

10 years ago

1.5.0

10 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.4

10 years ago

1.3.3

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.4

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago