@m0hammad/json-base v1.1.0
json-base
Database system built on modification to Json files.
Contents
Install
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 12.10.0 or newer is required.
Installation is done using the
npm install
command:
npm install @m0hammad/json-base
You can also install the latest version from Github using:
npm install M-0hamma-D/json-base
How to use
Setup the base:
const JsonBase = require("json-base");
const Database = new JsonBase(`./Databases`); // any path.
Create a database:
Database.create.database("database_name");
Create a table inside a database:
Database.create.table("database_name", "table_name");
Delete a database:
Database.delete.database("database_name");
Drop a table from a database:
Database.delete.table("database_name", "table_name");
Insert a row into a table:
Database.insert("database_name", "table_name", {key1: "value1", key2: "value2"});
Update row(s) keys and values:
Database.update("database_name", "table_name", {key2: "value3"}, {key2: "value2"});
Select row(s) from a table:
Database.select("database_name", "table_name", ["key1", "key2"], {key1: "value1"});
Delete row(s) from a table:
Database.delete.from("database_name", "table_name", {key2: "value3"});
The Inserted Object:
inserted_object
is the last parameter in the method insert
.
This parameter is the actual row to be inserted into the table.
Or it could be an array containing several rows to be inserted. If the array contains an empty row, it will be ignored.
The Update Object:
update_object
is the third parameter in the method update
.
This parameter is an object of keys' values to update.
If it doesn't contain the rest of the keys. the values of the rest of the keys will stay the same.
And if it contains keys that are not in the row, these keys will be added.
The Selection:
selection
is the third parameter in the method select
.
This parameter is an array that contains the keys to be selected from the rows.
The rest of the keys not included in the array will be ignored. If the array contains a key that is not in the row, the key value will be undefined.
The Filter Object:
filter_object
is the last parameter in the methods update, select, delete.from
.
This parameter makes the method filter the target table rows and match them with the object content
By matching values. But what if there is more than one potential value?
The method can be set to match more than one probability of a value by adding the parameter "||"
At the end of the method parameters, for example:
Database.select("database_name", "table_name", ["key1", "key2"], {key1: ["value1", "value_one", 1]}, "||");
In this case, the method will checks if the value of the key is array and matches the actual value of the key in the table with the values inside the array.
Upcoming Releases
Working on it ...