npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

modella-nedb

v0.1.0

Published

NeDB persistence adapter for modella

Downloads

4

Readme

modella-nedb

NeDB persistence for modella.

NeDB is a tiny embedded database, written in JavaScript, with a MongoDB-like API. It's ideal for prototyping, microservices, and desktop/CLI applications, and has a human-readable file format.

Modella is simple, extensible no-BS models for browser and server.

Install

$ npm install modella-nedb

Example

var nedb = require('modella-nedb')('./user.db')
var model = require('modella')

var User = model('User')
  .attr('_id')
  .attr('name')
  .attr('email', {unique:true})
  .attr('age')

User.use(nedb)

// query
User
  .query({age:{$gt:10}})
  .sort({age:-1})
  .exec(function(err, users){
    // users is an array of User instances
  })

API

plugin(opts)

Call the module function with opts to return a plugin. opts can be an object, a string file path, or an NeDB Datastore instance. Valid options are described in the NeDB docs.

Called without any options, the datastore will be in-memory, with no persistence.

var plugin = require('modella-nedb')
// all legit
plugin('./user.db')
plugin({filename:'./user.db'})
plugin(new Datastore('./user.db'))

Model#save(cb)

Saves a model's properties to disk and calls cb.

Model#remove(cb)

Removes a model from the db.

Model.find(query, cb)

Aliased to Model.get. Finds a single model using query.

Model.all(query[, cb])

Aliased to Model.query. Finds models using query, calls cb or returns a Cursor (see below).

Model.removeAll(query, cb)

Remove models matching query and calls cb.

Model.index(opts[, cb])

Set an index on the datastore. Options are:

  • fieldName Name of the field to index
  • unique Enforce uniqueness
  • sparse Don't index documents that don't have this field

You can also specify indexes in the model attributes, like this:

User
  .attr('age', {index:true})    // indexed
  .attr('email', {unique:true}) // unique

Model.db

NeDB Datastore instance. Use for direct database access.

Cursor

A call to Model.all/Model.query without a callback function returns a Cursor instance. This is the same as an NeDB cursor, but it will respond with an array of Model instances.

Cursor#sort(fields)

Sort the result set by an object of fields like {email:1, age:-1}.

Cursor#skip(n)

Skip n records in the result set.

Cursor#limit(n)

Limit the result set to n records.

Cursor#exec(fn)

Execute the query and call fn with the results.

License

MIT