🍩 Note: If you want a database with more features (e.g. math, etc.), I hightly recommend you looking at jsoning by @khalby786
A simplified and improved version of nmaggioni/Simple-JSONdb: a dead simple JSON database for your web app.
Install:: npm i qjson-db
or bun add qjson-db
if you're feeling extra fancy.
Start your database:
const qjson = require('qjson-db');
const db = new qjson('/path/to/your/storage.json');
Note: if you're using Glitch, you can store your db in the
.data
folder to keep it safe from other people viewing it. It will also not be included in remixes.
Then, you can use the functions:
db.set('key', 'value');
The key
parameter must be a string, value
can be whatever kind of object can be stored in JSON format.
db.get('key');
The key
parameter must be a string. If the key exists its value is returned, if it doesn't the function returns undefined
.
db.has('key');
The key
parameter must be a string. If the key exists true
is returned, if it doesn't the function returns false
.
db.delete('key');
The key
parameter must be a string. The function returns as per the delete operator if the key exists, else it returns undefined
.
db.JSON();
This will return a copy of the internal JSON storage object.
db.JSON({ data });
Giving a parameter to the JSON
function makes the object passed to replace the internal one. Be careful, as there's no way to recover the old object.