Skip to content
Schemaless, embeddable, Node.js database
Branch: master
Clone or download
Latest commit 43bcfae Dec 23, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE.md
README.md
db.js
eg.js
package.json

README.md

Ocelite

Schemaless, embeddable, Node.js database

Install

$ npm install ocelite

API

Db.init

Creates a connection to the database. Provide the filename of where to store the database file along with an array of items you're planning to store.

var Ocelite = require('ocelite');

var db = new Ocelite();
db.init('data.db', ['user'], callback);

Db.save

Saves an object to the database. First parameter is the item name matching one of the names provided in init. Second parameter is the data you're saving. The third is an optional parameter of data to index.

db.save('user', {name: 'Barbara Fusinska', twitter: 'basiafusinska'}, ['twitter'], callback);

Db.get

Access saved data by there index. First parameter is the type, followed by index name and the value. This returns an array of items.

db.get('user', 'twitter', 'basiafusinska', function(err, rows) { 
  console.log(rows);
});

Db.all

Return all the data saved for a particular type as an array.

db.all('user', function(err, rows) { 
  console.log(rows);
});

Example

var Ocelite = require('ocelite');

var db = new Ocelite();
db.init('data.db', ['user'], function() {
  db.save('user', {name: 'Barbara Fusinska', twitter: 'basiafusinska'}, ['twitter'], function() {
      db.get('user', 'twitter', 'basiafusinska', function(err, obj) {
        console.log(obj);
      });
 });
});

You can’t perform that action at this time.