Skip to content

tiagorangel1/qjson-db

 
 

Repository files navigation

🍩 Note: If you want a database with more features (e.g. math, etc.), I hightly recommend you looking at jsoning by @khalby786

qjson-db: Dead simple JSON database


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.

Usage

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:

Set a key

db.set('key', 'value');

The key parameter must be a string, value can be whatever kind of object can be stored in JSON format.

Read a key

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.

Check a key

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.

Delete a key

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.

Read JSON storage

db.JSON();

This will return a copy of the internal JSON storage object.

Replace JSON storage

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.

About

An easy-to-use JSON database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%