jsondatabase v1.2.4
JsonDB
To install, execute this in the command line:
npm i jsondatabase
Initializer
const JsonDB = require('jsondatabase');
const data = new JsonDB({
path: './path/to/file.json'
});
Add this to your node script, should probably be at the top.
If the file or paths don't exist, they will be created automatically.
SADD
data.sadd('setname', 'item');
Adds item
to setname
.
SREM
data.srem('setname', 'item');
Removes item
from setname
. If setname
becomes empty after calling srem
, it is deleted automatically.
SMEMBERS
data.smembers('setname');
Returns an array of items in setname
. If setname
doesn't exist, returns 0
.
HSET
data.hset('hashname', 'key', 'value');
Sets key
of hashname
to value
.
HGET
data.hget('hashname', 'key');
Returns the value of key
of hashname
. If key
of hashname
doesn't exist, returns 0
.
HDEL
data.hdel('hashname', 'key');
Deletes key
of hashname
. If hashname
becomes empty after hdel
is called, it is automatically deleted.
HKEYS
data.hkeys('hashname');
Returns an array of keys in hashname
. If hashname
doesn't exist, returns 0
.
HVALS
data.hvals('hashname');
Returns an array of values in keys of hashname
. If hashname
doesn't exist, returns 0
.
HGETALL
data.hgetall('hashname');
Returns an object of all keys in hashname
. If hashname
doesn't exist, returns 0
.
HLEN
data.hlen('hashname');
Returns amount of keys in hashname
. If hashname
doesn't exist, returns 0
.
HEXISTS
data.hexists('hashname');
Returns 1
if hashname
exists, 0
if it doesn't.
HINCRBY
data.hincrby('hashname', 'key', 'increment');
Adds increment
to key
of hashname
. If key
of hashname
is a string, it is set to 0. If key
of hashname
doesn't exist, returns 0
.
HINCR
data.hincr('hashname', 'key');
Adds 1 to key
of hashname
. If key
of hashname
is a string, it is set to 0. If key
of hashname
doesn't exist, returns 0
.
HDECRBY
data.hdecrby('hashname', 'key', 'decrement');
Subtracts decrement
from key
of hashname
. If key
of hashname
is a string, it is set to 0. If key
of hashname
doesn't exist, returns 0
.
HDECR
data.hdecr('hashname', 'key');
Subtracts 1 from key
of hashname
. If key
of hashname
is a string, it is set to 0. If key
of hashname
doesn't exist, returns 0
.
KGET
data.kget('keyname');
Returns the value of keyname
. If keyname
doesn't exist, returns 0
.
KSET
data.kset('keyname', 'value');
Sets keyname
to value
.
KDEL
data.kdel('keyname');
Deletes keyname
. If keyname
doesn't exist, returns 0
.
KEYS
data.keys();
Returns an array of all keys.
KEXISTS
data.kexists('keyname');
Returns 1
if keyname
exists, 0
if it doesn't.
KRENAME
data.krename('oldkey', 'newkey');
Renames oldkey
to newkey
. If oldkey
doesn't exist returns 0
. If newkey
exists it will be overwritten.
KINCRBY
data.kincrby('key', 'increment');
Adds increment
to key
. If key
is a string, it is set to 0. If key
doesn't exist, returns 0
.
KINCR
data.kincr('key');
Adds 1 to key
. If key
is a string, it is set to 0. If key
doesn't exist, returns 0
.
KDECRBY
data.kdecrby('key', 'decrement');
Subtracts decrement
from key
. If key
is a string, it is set to 0. If key
doesn't exist, returns 0
.
KDECR
data.kdecr('key');
Subtracts 1 from key
. If key
is a string, it is set to 0. If key
doesn't exist, returns 0
.