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

jsormdb

v1.3.2

Published

A JavaScript library for embedded database with persistence to the server or other stores

Downloads

3

Readme

jsormdb node module (node-jsormdb)

This is a wrapper node module for the jsorm database done by Avi Deitcher. It also exposes a simple JSONDatabase to automate the persisting of the database to the disk.

Building from source

Clone the repository in a jsormdb folder inside a node_module directory.

git clone git://github.com/andreasbotsikas/node-jsormdb.git jsormdb
git submodule update 

Note: jsormdb (in the src folder) is linked to this repo and requires "submodule update" to update from the original repository.

Getting jsormdb

Avi Deitcher's jsorm database can be either downloaded from the official website or be compiled from source.

If you want to skip building, go to http://jsorm.com/wiki/Download and download jsormdb archive. Place the jsormdb.js in the lib folder and you are ready to go.

If you want to build the jsormdb.js just run ant in the root of this repository.

jsormdb> ant 

Usage

The module exposes two objects:

  • JSORM: The jsorm object as described in its own wiki page
  • JSONDatabase: A simple database wrapper to persist the changes automatically on the hard disk

Since the JSORM object has not been modified at all, the best resource on using it is the official website and the dedicated wiki page.

JSONDatabase object has a simple constructor that takes an optional configuration object as a parameter. The configuration object has the following optional fields:

  • path: path to the database file. Default './database.json'.
  • transactional: Set database in transactional mode. Requires commit of insert and remove operations in order to persist in database. Defaults to false.
  • debug: Set database in debug mode. Defaults to false.

The JSONDatabase object exposes the following simple functions:

  • insert( object[] ): Inserts an array of objects in the db. Persists it if not in transactional mode. Internally it uses jsormdb's insert.
  • remove( query ): Removes the items matching the provided 'where' query. Internally it uses jsormdb's remove.
  • query ( query ): Search by query. Returns an array of records. Internally it uses jsormdb's find.
  • rollback: Rollback all changes since last commit. Internally it uses jsormdb's reject.
  • commit: Commit existing transaction and persist changes to the disk file. Internally it uses jsormdb's commit.

For query syntax check jsormdb's wiki page.

The JSONDatabase object exposes the internal jsormdb through its db property.

Examples

The following examples are located in the examples folder and you can test them by running:

jsormdb/examples> node JSONDatabase.js
jsormdb/examples> node JSORM.js

JSONDatabase

// Require the module
var databaseHelper = require('jsormdb');
// Create the database object loading data.json if it exists
var myDB = new databaseHelper.JSONDatabase({path : './data.json', transactional : false});
// Drop all existing entries
myDB.remove();
// Dummy data
var dataToInsert = [{id: 1, name:"webinos project", website:"http://www.webinos.org"}];
// Insert data to db
myDB.insert(dataToInsert);
var moreData = [
	{id: 2, name:"Avi Deitcher", website: "https://github.com/deitch"},
	{id: 3, name: "jsorm website", website: "http://jsorm.com"}
];
// Insert data to db
myDB.insert(moreData);
// Get all data
var result = myDB.query(); // Equivelant to myDB.db.find();
// Display them
console.log("The db has the following entries:");
console.log(result);

// Query for the first entry
var query = { field: "id", compare: "equals", value: 1 };
// The following is quivelant to myDB.db.find({where: query});
result = myDB.query({where: query});
console.log("The " + result[0].name + "'s website is : " + result[0].website);

// Query for the Avi's github url and pick only that field
query = { field: "name", compare: "contains", value: "Avi" };
var fields = { website: true };
// The following is quivelant to myDB.db.find({where: query, fields: fields});
result = myDB.query({where: query, fields: fields});
process.stdout.write("Avi Deitcher's github url is ");
console.log(result[0].website);

// Remove entry with id==3
myDB.remove({where: { field: "id", compare: "equals", value: 3 }});

Please refer to the excellent jsormdb wiki for querying details and for advanced use of the jsormdb database.

JSORM

The same example applies but instead of using:

var myDB = new databaseHelper.JSONDatabase({path : './data.json', transactional : false});

use:

var myDB = new databaseHelper.JSORM.db.db({parser: databaseHelper.JSORM.db.parser.json(), writeMode: databaseHelper.JSORM.db.db.modes.replace});

and instead of the query method call find.

Disclaimer

This code was initially written for the purposes of the webinos project. It is distributed freely under the Apache 2.0 license.

All the hard work of creating the jsormdb is done solely by Avi Deitcher.

A special thank you is in order to the following webinos members:

  • Heiko Desruelle for bringing the jsormdb module idea and writting the initial implementation.
  • Christos Ntanos for adding this module to the webinos platform and testing it thoroughly.