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

nedb-wrap

v1.0.1

Published

wrapper and helper around ned lib

Downloads

1

Readme

nedb-wrap

nedb-wrap is a very simple wrapper around nedb a local small lightweight no-sql dtabase similiar to mongodb

The original nedb npm package is available below https://www.npmjs.com/package/nedb

Installation

npm install --save nedb-wrap

# Or install it globally
npm install -g nedb-wrap

Usage

Importing and Setting a Database location in your Project

let dataBasePath = "Some/location/in/your/Project"
let Schema = require("nedb-wrap").createSchema(dataBasePath)

Common arguments:

  • dataBasePath The Location where nedb should create the DB file

  • collectionName The Name of the Collection the model data should be stored in

  • query A object containing a specific Query to query the Collection ex: {field1:"TestField1"} a query to find objects where field1 is TestField1

Adding a New Collection & Data to your DB

let collectionName = "Test-Collection-Name";

let testModel ={
    field1:"TestField1",
    field2:"TestField2",
    field3:"TestField3",
}

let testDbEntry = await Schema.setModel(testModel).Model().add(collectionName)
console.log(testDbEntry);

Retrieving Collection Data By Specific Key and Value


let model = await Schema.Model().getBy("Test-Collection-Name",{field1:"TestField1"});

Retrieving Collection Data Mongo DB Style queries and projections

please see https://www.npmjs.com/package/nedb for more info on how and what queries are supported.

let collectionName = "Test-Collection-Name";

let model ={
  field1:"TestField1",
  field2:"TestField2",
  field3:"TestField3",
}
let docs = await Schema.Model().find(collectionName, { field1: 'TestField1' }, { field1: 1, field2: 1, field3: 0, _id:0 });

// docs is [{field1:"TestField1",field2:"TestField2"}]

Raw Cursor and Pagination

please see https://www.npmjs.com/package/nedb for more info on how to use cursors and Pagination. This is Copy Pasta from Nedb README.md just slightly adjusted for the nedb-wrap usage

// Let's say the database contains these 4 documents
// doc1 = { _id: 'id1', planet: 'Mars', system: 'solar', inhabited: false, satellites: ['Phobos', 'Deimos'] }
// doc2 = { _id: 'id2', planet: 'Earth', system: 'solar', inhabited: true, humans: { genders: 2, eyes: true } }
// doc3 = { _id: 'id3', planet: 'Jupiter', system: 'solar', inhabited: false }
// doc4 = { _id: 'id4', planet: 'Omicron Persei 8', system: 'futurama', inhabited: true, humans: { genders: 7 } }

let collectionName = "Test-Collection-Name"
// No query used means all results are returned (before the Cursor modifiers)
Schema.Model().cursor(collectionName).find().sort({ planet: 1 }).skip(1).limit(2).exec(function (err, docs) {
  // docs is [doc3, doc1]
});

// You can sort in reverse order like this
Schema.Model().cursor(collectionName).find().sort({ planet: -1 }).exec(function (err, docs) {
  // docs is [doc1, doc3, doc2]
});

// You can sort on one field, then another, and so on like this:
Schema.Model().cursor(collectionName).find().sort({ firstField: 1, secondField: -1 })

Retrieving all Collections


let model = await Schema.Model().getAll("Test-Collection-Name");

Updating a model in a Collection

let testModelUpdated ={
    field1:"TestField1-Updated",
    field2:"TestField2",
    field3:"TestField3",
}
await Schema.Model().update("Test-Collection-Name",testModelUpdated);

Counting Records in the Collection

let count = await Schema.Model().count("Test-Collection-Name",{field1:"TestField1"}) // Count records with a specific key and Values
let count = await Schema.Model().countAll("Test-Collection-Name")                    // count all Records for given Collection

Deleting Collection Models

await Schema.Model().delete("Test-Collection-Name",testDbEntry); // Delete a Model in the Collection
await Schema.Model().deleteAll("Test-Collection-Name");        // Delete all Models in the Collection

Have a look the test examples to get a better understanding how to use this module!