database-2.js

2.2.0 • Public • Published

Database 2

Database 2 is a new modern nosql, file path based database.

It needs the same amount of ram for datas ranging from 1mb to 1e+75TB, no ram difference for data!

This package contains 2 separate classes Client and Server

Performance Server

This is the ClustedServer function inside the package. It creates multiple server instances but costs a lot of resources

const {ClustedServer} = require("database-2.js");

ClustedServer(instances, port, users, callback fn)

Instances

Number of instances to run (for eg. 800, min 1)

WARNING

Costs a lot of resources

port & users & callback fn

See constructor props

Server

The server is the backend of the database wrapper. It should be always 24/7 running in order for database to work.

Methods

All methods

Constructor

connect

shutdown

get

exists

set

add

subtract

delete

Constructor

Inputs

port

Number | String

users

    Array[]{
         name: string, 
         passsord: string, 
         role: "all" | "read" | "write" | "delete" | Array<"read" | "write" | "delete" | "all">
    }

Callback Fn (optional)

         function (event, ...args) {

         }
Event
              error (if any error occured)
                       > Error Stack
              ready
                       > Port
              blocked-request
                       > Request Object
                       > Response Object
                       > Status Code Sent
                       > Json Msg Sent
              allowed-request
                       > Request
                       > Response
              blocked-read
                       > Request 
                       > Response
              allowed-read
                       > Request
                       > Response
              blocked-write
                       > Request
                       > Response
              allowed-write
                       > Request
                       > Response
              blocked-delete
                       > Request
                       > Response
              allowed-delete
                       > Request
                       > Response
const {Server} = require("database-2.js");

const users = [
         {
                  name: "ahq", //It is used to identify the user
                  password: "1234", //It will be hashed and stored in RAM
                  role: "all" //read, write, delete
         }
];

const logFn = (event, ...args) => {
         console.log(`${event} occured with args: `, ...args);
}

const Database = new Server(3000, users, logsFn);

Connect

Connects the database

Database.connect();

Shutdown

Kills the process and shutdowns the database. (Cannot be done in the client side)

Database.shutdown();

get

Gets data with relative paths. Client Side Permission "read" required

Input

path > relative path (eg. "database/store", "database" is where the key "store" is located)

Output

String (JSON string)

console.log(JSON.parse(Database.get("myservice/accounts/account-a")));

exists

Check if file exists. Client side permission "read" required

Inputs

path > relative path

Output

Boolean (true/false)

console.log(Database.exists("keys/user1"));

set

Sets data to a relative path. Client side permission "write" required.

Inputs

path > relative path

data > JSON stringified data () > JSON.stringify(any)

Database.set("myservice/accounts/account-a", JSON.stringify({name: "AHQ"}));

add

Adds data to a relative path. Client side permission "write" required

WARNING

For numbers only

Inputs

path > relative path

number > Number to subtract

Database.add("some/value", 1);

subtract

Subtracts data to a relative path. Client side permission "write" required

WARNING

For numbers only

Inputs

path > relative path

number > Number to subtract

Database.add("some/value", 1);

delete

Deletes data from a relative path. Client side permission "delete" required

Inputs

path > relative path

Database.delete("some/value");

Client

Module coming soon!

Readme

Keywords

none

Package Sidebar

Install

npm i database-2.js

Weekly Downloads

0

Version

2.2.0

License

ISC

Unpacked Size

146 kB

Total Files

1816

Last publish

Collaborators

  • ahqahqahqahq