Skip to content

maakep/database-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Weekly downloads

Object-to-file, JSON database

Featherweight writing and reading object to/from json files.

Installation

npm i object-to-file --save

Module usage

Try it out in RunKit

https://npm.runkit.com/object-to-file

var objectToFile = require("object-to-file")
var db = new objectToFile.default("testing-runkit");
db.push("Greeting", { Hello: "World"});
db.read("Greeting");

Docs

Creating database

Create a database named "database-name":

import Database from 'object-to-file';
var db = new Database("database-name");

// or...

var objectToFile = require("object-to-file");
var db = new objectToFile.default("database-name");

An empty database-name.json will be created.

Updating

Create "MyTesting" key and push an object to it:

db.push("MyTesting", { hello: "world" });

Reading

Single key

Get the object(s) of MyTesting key:

db.read("MyTesting");

object returned:

{ "hello": "world" }

Everything

Read entire file:

db.read(); 

object returned:

"MyTesting": {
    "hello": "world"
}

Deleting

Remove everything under "MyTesting" and the key:

db.delete("MyTesting");

Remove all data:

db.truncate();

Permanently remove the database (file):

db.unlink();

Test

ts-jest to run tests (not included in )

npm run test

About

Featherweight writing and reading object to/from json files

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published