🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

superjson-db

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superjson-db

SuperJson DB - library javascript for DB easy and flash

npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

SuperJson

A little custom made, document-oriented database project made with JavaScript and JSON for convenience.

Setup

const Wasteful = require('SuperJson');
const db = new Wasteful({feedback: true, path: `${__dirname}/data/`, serial: true});

Overall Requirements:

  • NodeJS v14.17.6 or higher
  • NPM v6.14.15 or higher

Functions

/*
  db.insert();
    
  db.find();
  
  db.get();

  db.delete();
  
  db.update();

  db.collect();

  db.size();

  db.check();
    
*/

db.insert({id: "1234", name: "seth", pass: "xyz"}); // An "id" variable is required in every insertion.

db.find({id: "1234"}); // Functions with or without an object for the identifier.

db.get("1234", (result) => {
    console.log(result);
})

db.update({id: "1234", element: "pass", change: "abc"});

db.collect();

db.size();

db.check("1234");
db.check({id: "1234"});

db.delete({id: "1234"});
db.delete("1234");

SuperJson Interface

(Only available in Github repo)

A newly developed form of interacting with your data stored via SuperJson; A command-line interface which could be used for quick changes or personal usage without the hastle of typing a whole new set of code.

The interface file can be found within the "SuperJson" folder likely located in your node_modules folder and is named "SuperJson Interface"! (A shortcut to "wastefulbat" for design reasons.)

When launching the interface, you simple press a number listed in the options menu, press enter, and provide the information needed to execute an action!

Interface Requirement(s):

  • npm i chalk (this should already be installed in the package itself)

In Depth

new Wasteful({feedback: true, path: `${__dirname}/info/`});
  • feedback - Sends a confirmation via console when a function is executed successfully. (default: false)
  • path - Provide a custom path where you wish JSON files to be written/read. (default: .../SuperJson/data/)
  • serial - Automatically assigns filenames/identifiers based on the size of the set path. (default: false)

.insert()

Insert a file with as many variables as you wish. Always include an "id" variable as that is what is use to read the JSON document in most cases.

db.insert({id: "1234", name: "seth", pass: "xyz"});
  • id - The name of the file and what will be used in the .find() function

.find()

Provides the information of the specified file with the matching identifier.

let info = db.find({id: "1234"});
console.log(info);
  • id - The identifier of the file to find and display the information of.

.get()

Unlike db.find, db.get will read each JSON file within the directory and read each identifier within to locate the specified file.

db.get({id: "4321"}, async(res) => { console.log(await res) });
  • id - The internal identifier of a file.

.update() (by identifier)

db.update({id: "1234", element: "id", change: "4321", math: false});
  • id - The name/id of the file to update
  • element - What element of the file you want to update
  • change - What change you want to make to it
  • math? - Does the change require (simple) math?

.update() (by element content)

db.update({element: "age", change: 1, math: true}, {name: "animal", content: "fox"});
  • name - The name of an element within a file to check.
  • content - The contents to be matched with the contents of the given element.

.update() (child element)

Update the value of an element's "child" or sub-value of the given element. "Child" is referred to as a nested collection element/value within your file.

db.update({element: "name", child: "first", change: "Mike", math: false}, {name: "animal", content: "fox"});
  • element - The parent element within a file which houses the child element (i.e nested collection).
  • child - The child of the provided 'element' to be changed.

.collect({id?, element?})

Reads, parses, then pushes information from each JSON file into one collection. Provide an id and/or element to further filter through each file.

let data = db.collect();
data.forEach(info => {
  if(info.active == true) {
    console.log(info);
  } else {
    return;
  }
})

Keywords

db

FAQs

Package last updated on 23 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts