@web_dev_guy/jdb-js v1.0.32
WELCOME TO JDB.JS
this page will discuss how to operate with JDB.JS.
What is JDB.JS?
JDB.JS is meant to be a NoSQL JSON database that people could use.
Dependencies
fspathxml2jstoml@iarna/tomlyamlpython-shell
Installation
npm install @web_dev_guy/jdb-js
Linking to your Project Using NPM
Import
import JDB from "@web_dev_guy/jdb-js";
Require
const { JDB } = require("@web_dev_guy/jdb-js");
JDB Class -
This is the class which contains all the functions that you can use the first parameter is the name of your file you will be preforming CRUD on
const { JDB } = require("./JDB/JDB.js") or require("@web_dev_guy/jdb-js");
const jdb = new JDB("jsonfile");
// links to "jsonfile.json" in the JDBF foldernow we will disscuss the functions in the JDB class
readData()-- this function reads the file that you have put as the parameter in the class's constructor.
writeData(data : String)-- this function writes the
datainto the JDBF (Json DataBase Files) , this WILL delete the rest of the contents in the file. The syntax to writing the json data in this function and other like functions is'"key1" : "value1", "key2" : "value2"'.
- this function writes the
setData(key : String, value : String | Int)-- this is basically writeData, but it dosnt delete the existing contents and can only write new data once. It can also change the value of any key you put as the first param any time.
getData(key : String)-- this function will get the value of the key which has the same name as the
keyparam.
- this function will get the value of the key which has the same name as the
addData(key : String, value: String | Int)-- this function appends data (
"{key}" : "{value}") to the file instead of deleteing the already existing contents.
- this function appends data (
addBigData(code : String | Int)-- this is just add function but you could add lines of JSON code.
removeData(key : String)-- this function removes the key and its value from the JDBF code.
removeAllData(brackets : Boolean)-- removes all the code from the file, if brackets is true, then the brackets will also be delete, else the brackets will.
hasData(value : String | Int, returnBool : Boolean)-- returns the name of the key that contains the value that is equal to
valueifreturnBoolis false, else it returns a bool value.
- returns the name of the key that contains the value that is equal to
setKey(name : String, newname : String)-- changes the key's name from
nametonewname.
- changes the key's name from
replaceUrl(new_url : String)-- changes the url of the JDB class to the value of
new_url.
- changes the url of the JDB class to the value of
terminate()-- terminates the JDB code
onReadData(callback(txt : String) : Function)-- after reading the JDBF and returning the json it will run the
callbackfunction that has the param oftxtwhich contains the content of the JDB.
- after reading the JDBF and returning the json it will run the
onWriteData(words : String | Int, callback: Function)-- after writing the data it runs the
callbackfunction.
- after writing the data it runs the
onAddData(text : String | Int, callback : Function)-- its
onWriteDatabut it dosnt delete the existing contents of the text.
- its
onRemoveData(name : String, callback : Function)-- when a key thats equal to
nameis removed, the thecallbackfunction triggers.
- when a key thats equal to
limitData(by : Int)-- basically the
LIMITkeyword in sql wherebyis the least amount of values returned. It returns the value in[{key : key_name}, {value : value_value }]format.
- basically the
keyExists(key : String)-- checks if
keyis a key in the JDBF, if its there than it returnstrue, elsefalse.
- checks if
valueExists(value : String | Int)-- checks if
valueis a value in the JDBF, if its there than it returnstrue, elsefalse.
- checks if
countData()-- returns the count of keys in a JDBF.
whereKey(key : String)-- finds the
keyand returns its position in the JDBF.
- finds the
whereValue(value : String | Int)-- finds the
valueand returns its position in the JDBF.
- finds the
sortData(by : String, type : String)-- Sorts the keys or values, you can choose by changing the
byparam, in the JSON data based on the specified criteria thats in thetypeparam.
- Sorts the keys or values, you can choose by changing the
unionData(state1 : String, state2 : String, stringing : Boolean)-- merges
state1andstate2together, if you want it stringifyed, setstringingtotrue.
- merges
intersectData(state1 : String, state2 : String, stringing : Boolean)-- takes the 2 states and returns the common values and it could be converted to json by setting
stringingtotrue.
- takes the 2 states and returns the common values and it could be converted to json by setting
differenceData(state1 : String, state2 : String, stringing : Boolean)-- takes the 2 states and returns the different values cand it could be converted into json by setting the
stringingtotrue.
- takes the 2 states and returns the different values cand it could be converted into json by setting the
lenData()-- returns the length of the JDBF.
watchData(callback : Function)-- watches the data of the current file and runs the
callbackwhenever the data is changed.
- watches the data of the current file and runs the
watchDataInterval(callback : Function, interval : Int)-- watches the data every
intervalin the current file and runscallback-whenever the data is changed.
- watches the data every
runWithPythonFirst(func : Function, code : String | I/O Wrapper, isfile : Boolean, returnpython : Boolean)-- first runs python code given in
codeand runs it depending on ifisfileistrueorfalse, if true then it will readcodeas a I/O, meaning read from file. This function WILL NOT run if you just give the file path, you must use node filesystem for this. If you want the function to return the python value, then setreturnpythonto true. After the python code it will run the js code, which the python func output can be used in.
- first runs python code given in
runWithPythonLast(func : Function, code : String | I/O Wrapper, isfile : Boolean)-
same as
runWithPythonFirstbut js runs first and that the js function wont get the return value from the python code to its advantage.note that these 2 python functions require the actual python language to be ran correctly.
JDBFS Class -
there are also functions can help you do stuff with files, rather than keys and value in the JDB class
CreateJDBF(name : String) -
- This creates a new JDBF in the JDBF folder which has
{}as the starting content.
DestroyJDBF(name : String) -
- This destorys or deletes the JDBF from the JDBF folder.
IntegrateJDBF(oldf : String, newf : String)
- This moves the data from the file named
oldfto the file namednewf.
DuplicateJDBF(file : String, name : String) -
- This duplicates the file named
file. then the duplicated file name isname.
HookJDBF(fileone : String, filetwo : String) -
- This makes
filetwoalways have the contents offileone.
ImportasJDBF(file : String, type : String, name : String) -
- this function imports code from a file named
filewhich you can specify its file type in thetypeparam into a JDBF namedname, Note: if you have the file in a folde in the root dir, you should add the folders name to your url e.g - FOLDER_NAME/FILE_NAME.
ExportJDBF(file : String, type : String, name : String)-
- export jdbf named
fileto a file named namenamewhich is atypeformat.
BackupJDBF(file : String)-
- makes a backup jdbf of
filewith the.bak.jsonfile format which will be in the place of the main jdbf if the main one isnt found.
RestoreJDBF(file : String)-
- restores the
.bak.jsonfile namedfileto a.jsonfile namedfile.
MergeJDBF(fileone : String, filetwo : String, name : String)-
- merges jdbf's named
fileoneandfiletwointo one file that would be namedname.
DiffJDBF(fileone : String, filetwo : String, name : String)-
- The DiffJDBF() function takes in two JSON files (
fileoneandfiletwo) and a new filename (name). It reads the content of these JSON files, parses the data into JavaScript objects, and then compares the keys of the first file with the keys of the second file.
PythonWithJDBF(file : String, var_name : String, code : String | I/O Wrapper, isfile : Boolean)-
- This function will run python code specified in
codeand it will differently if it is a file, if yes, then setisfiletotrue. you wont need to import json as the code will do that for you. the variable which will contain the json code from thefilecan be set using thevar_name. Again YOU WILL NEED PYTHON LANG FOR THIS TO WORK.
Syntax
const { JDBFS } = require("./JDB/JDB.js") or require("@web_dev_guy/jdb-js");
const jdbfs = new JDBFS();
jdbfs.CreateJDBF("example"); // creates new JDBF called example
// ...
jdbfs.IntegrateJDBF("example", "main"); // moves data from example.json to main.json
jdbfs.HookJDBF("main", "main2"); // main is now hooked to main
jdbfs.Duplicate("main", "main_dup"); // duplicated main and renamed the duplicate to main_dup
jdbfs.DestroyJDBF("example"); // destroys the JDBF called exampleExample Usage:
// Create a new JDBFS instance
const jdbfs = new JDBFS();
// Create a JDB file
jdbfs.CreateJDBF("example");
// Create a new JDB instance
const jdb = new JDB("example");
// Write data to the JDB file
jdb.writeData('"name" : "john", "age" : "twenty-two", "month_of_birth" : "jan"');
// Set a new value for a key in the JSON data
jdb.setData("name", "alex");
// Read and log data from the JDB file asynchronously
jdb.onReadData((data) => {
console.log(data);
});
// Delete the JDB file
jdbfs.DestroyJDBF("example");
// Terminate the JDB instance
jdb.terminate();Developer Note
enjoy these new JDBFS funcs
Upcoming Features
- JDB CLI
- JDB IMPORTS
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago