Skip to content

File-system based database compatible with the Database Stream API

License

Notifications You must be signed in to change notification settings

avinoamr/dbstream-fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbstream-fs

File-system based database compatible with the dbstream API.

This implementation doesn't implement any indexing logic, which means that the database performance will scale proportionally to the data size. It's recommended to only use it in development environments or very tiny applications.

Usage

var db = require("dbstream-fs");
var connection = db.connect( "file-path" );

// write or update
var cursor = new connection.Cursor()
cursor.write({ id: 1, name: "Hello" });
cursor.write({ id: 2, name: "World" });
cursor.on("finish", function() {
  console.log("Saved 2 objects");
});
cursor.end();

// read
new connection.Cursor()
  .find({ id: 2 })
  .limit( 1 )
  .on("data", function (obj) {
    console.log("Loaded", obj);
  });

API

This module implements the dbstream API. For the complete documention see: https://github.com/avinoamr/dbstream

connect( [file-path] )
  • file-path a String path to the database file to be used
  • Returns a dbstream Connection object
Connection.compact( destination-path )
  • destination-path is a String path to the desination file

This method will compact the size of the DB file by removing duplicate or obsolete lines. This is useful because this module always maintains the file in append-mode in order to avoid conflicts and locks. Every insertion, update or even removal will append another line to the file which will therefore always get bigger. You may want to run this command periodically in order to create a new database file that is move concise.

About

File-system based database compatible with the Database Stream API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published