7

GitHub - kutluturk/memdb-json: Very fast in memory object DB for Node.JS.

 2 years ago
source link: https://github.com/kutluturk/memdb-json
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

In-Memory Database For JSON Objects that can be queried like SQL

This package is intended to be used as a drop-in small footprint Object database solution for Node.JS.

How to Install

npm install --save memdb-json

Usage

This package is still in alpha stage. Please be aware before using in production environment.

Initialization

const memdb = require('memdb-json');
const MemDB = new memdb(pathToFile); //path to optional JSON file 

You can pass an optional JSON file path to the function for persistant data storage.

Insert an object to the DB

MemDB.insert({id: 1, Name: "Halil", Surname: "Kutluturk", Age: 45, City: "Berlin", Country: "Germany"});

Returns a UUID of the object inserted to the DB

Select object(s) from the DB

MemDB.select({where: {City: "Berlin"}});
MemDB.select({where: {Surname: "Smith", Age: 45}}); // You can add multiple keywords
MemDB.select(); //Returns all objects

You can query the DB with "where" keyword.
Returns an array of JSON Objects

Update an Object in the DB

MemDB.update({where: {id: 1}, set: {Born: "New York", Surname: "John", Born: "1998-01-01"}});
MemDB.update({where: {Name: "John", Surname: "Smith", Nationality: "USA"}, set: {Born: "New York", Active: true}});

Returns a JSON array with updated Objects

Delete object(s) from the DB

MemDB.delete({where: {id: 1}})

Empty (truncate) the DB

MemDB.truncate();

Save the Objects in the DB to a JSON file (persistant data storage)

MemDB.save(pathToFile);

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK