ldbjs
A lib to create and manage local db files and data, whit a simple send and get system,
save any data, html content, js objects and arrays, JSON, some texts, anything.
The erros in the operations is automatically returned not include in yours callbacks.
Creating a db location folder
const ldb = ; ldb; // optional callback // this function create ldb DB and json DBldb;
And your db are created.
Creating DB file
const ldb = ; ldb; // optional callbackldb; // optional callback // ldb.createDBFile(path, db, file);
The file extension are .ldb.
Sending data to my dbfile
const ldb = ; ldb;ldb; let myData = 'Hello World!'; ldb;
Sent data is saved exactly as sent
Getting data from dbfile
const ldb = ; ldb;
The returned value is the data of the file.
This function is used only with a callback to get the parameter.
Getting the DB files list
const ldb = ; ldb; ldb;ldb;ldbjson; // this return a table on console with the all files in the dbldb;
To use a callback in that function use like this
ldb;
This function return the files name.
To overwrite data of the file
const ldb = ; ldb;ldb; let myData = 'I overwrited data!'; ldb; // optional callback
That action is irreversible.
Cloning the content to other dbfile
const ldb = ; ldb;ldb; let myData = 'I overwrited data!'; ldb; // optional callback ldb;
To clone a file you need the two files created.
Deleting a dbfile
const ldb = ; ldb;
That action is irreversible.
To rename a dbfile
const ldb = ; ldb;
This function not receive a callback, are shown in the console the new stats of the file
Using events
const ldb = ; ldbevent; ldbevent;
Events are a very simple way to create and manage DBs and DBfiles in your application, don't repeat code anymore.
Sending and getting data from json
const ldb = ; // creating a json dbfileldbjson; // sending the data let myJSObj = name: "Jhon" age: 27; ldbjson; // getting the dataldbjson;
While a data are getted a js obj are return, the api automatically convert the json to a js object for you.
JSON insert and delete
const ldb = ; ldbjson; let myJSObj = name: "Jhon" age: 27 parents: bro: "Fred" ; ldbjson; // without argsldbjson; // with argsldbjson; // to create new propertyldbjson; // to delete a propertyldbjson;
To insert data use the index propertie to put a new value, this function must
have a json file not empty to work.
JSON push, add and remove
const ldb = ; ldbjson; let obj = arr: ; ldbjson;ldbjson;// push 1 to json 'arr' arrayldbjson;// add sum 2 to json 'arr' array // results its like {"arr": [3]} ldbjson;// remove 1 from original value 3 // results its like {"arr": [2]}
Base64 encode and decode
const ldb = ; let str = 'Hello World!'; // to encode a stringldbbase64;// returns SGVsbG8gV29ybGQh // to decode a stringldbbase64;// returns Hello World!
This process use the base-64 module, this is downloaded like a dependecie.
Backup and rollback
const ldb = ; ldb;// create a fileName.backup.ldb file ldb;// get the fileName.backup.ldb data and put in fileName.ldb // To use in json is very similar, put the json moduleldbjson;// use the same logic