Giter Club home page Giter Club logo

modella-leveldb's Introduction

LevelDB

LevelDB plugin for modella.

Installation

npm install modella-leveldb

Example

var model = require('modella');
var level = require('modella-leveldb')('./mydb');
var uid = require('uid');

var User = model('user')
  .attr('id')
  .attr('name')
  .attr('email')
  .attr('password');

User.use(level);

/**
 * Initialize
 */

var user = new User;

user.id(uid(6))
    .name('matt')
    .email('[email protected]')
    .password('test');

user.save(function(err) {
  console.log(user.toJSON());
});

API

Level(path|db, options)

Initialize leveldb with a path to the database. If path doesn't exist, it will be created. options will be passed through to levelup

Alternatively, you can pass your own level db instance in.

Model.index(index, opts)

Create a secondary index using leveldex. You may ensure that key is unique by passing unique : true in opts.

User.index('email', { unique: true });

Model.all([options], fn)

Get all models (static method)

Model.find(id|object, [options], fn)

Find a model (static method).

If you provide a secondary index, you can search by that key:

Model.find({ email: '[email protected]' } , fn);

model.save([options], fn)

Save the model (instance method)

model.remove([options], fn)

Remove the model (instance method)

All options will be passed through to levelup.

License

MIT

modella-leveldb's People

Contributors

matthewmueller avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.