This is a json database holder which creates a json file in the same directory as where this module is stored.
This is similiar to quick.db, very simple, fast, and perfect for beginners.
- Update! v2.5.2
- db.push()
- Update! v2.5.1
- Database names to enable multiple databases per project. Not required, but you should use if you want to have multiple Databases for one project. Defaults to "jsondb"
const Database = require("@localsimp/quick-json.db") // requiring it
const db = new Database("coolDB"); //initialize new database client. Creating jsondb file with the name given if it does not exist.
// you dont have to provide ".json" just give it any name that'll seperate it from your other projects
db.set("key","value") //sets value to key.
db.get("key") // returns value of key or null
db.delete("key")// removes key from database
db.all() /*returns array with json in each index. if db.all() is assigned to the constant "data" then
data[index].key returns the key and data[index].value returns the value
*/
db.add("key",number) /*sets the key to 0 if it doesnt exist else adds the number given to
existing number value*/
db.subtract("key",number) // same as above but subtracts
db.ping(method) // the method can be "set", "get" or "all". Returns response time of the operation
db.clear() // clears all data in database
db.push("key",anyvalue) // creates an array in the database with the key if it doesnt already exist. if it does, it pushes to the array.