@sectly-studios/suchdb
v1.0.16
Published
An simple, dependency free, require & go node.js and browser database
Downloads
31
Readme
SuchDB: An simple, dependency free, require & go node.js and browser database
Install: npm i @sectly-studios/suchdb
| (https://www.npmjs.com/package/@sectly-studios/suchdb)
Quick Start:
let SuchDB = require("@sectly-studios/suchdb");
let database = new SuchDB.SuchDB({}); // Make an new database instance
database.set("foo", "bar") // Lets add some data
database.get("foo") // Lets grab the data, It should return: bar
database.set("foo", { bar: [1, 2, 3, 4], baz: { name: "SuchDB" } }) // SuchDB Supports: Strings, Numbers, Objects And Arrays As Values
database.get("foo") // { bar: [1, 2, 3, 4], baz: { name: "SuchDB" } })
database.get("foo").bar // [1, 2, 3, 4]
database.get("foo").bar[0] // 1
database.get("foo").baz // { name: "SuchDB" }
database.get("foo").baz["name"] // SuchDB
Docs:
Table of Contents
- exports
- set
- get
- remove
- clear
- keys
- values
- entries
- forEach
- size
- isEmpty
- has
- lookup
- sort
- save
- load
- raw
- Boot
- Find
- FindMultiple
exports
Browser:
Load in file with:
<script src="path/to/suchdb"></script>
let database = SuchDB.SuchDB();
Node.js:
let SuchDB = require("@sectly-studios/suchdb");
let database = new SuchDB.SuchDB();
Options/Config:
let SuchDB = require("@sectly-studios/suchdb").SuchDB({
master: "data",
autosave: true,
autoload: false,
encrypt: {
enabled: true,
key: "SuchDB_Key",
},
autobackup: true,
logging: true,
custom_logging : function(message) {
// Some code to log to something like logtail or sentry.
}
});
set
Set/Add Data To The Database
Parameters
key
stringvalue
any
database.get(key, value)
get
Get/Grab Data From The Database
Parameters
key
string
database.get(key) // Returns data
remove
Remove/Delete Data From The Database
Parameters
key
string
database.remove(key)
clear
Clear/Delete All Data In The Database
database.clear()
keys
Get Database Keys
database.keys() // Returns keys
values
Get Database Values
database.values() // Returns values
entries
Get Database Entries
database.entries() // Returns object
forEach
Loop Through All Data In The Database
Parameters
callback
function (key, value)
database.forEach(function(key, value) {
// Retuns key and value
})
size
Get Database Size
database.size() // Returns number
isEmpty
Check If Database Is Empty
database.isEmpty() // Returns boolean
has
Check If Database Has Data
Parameters
key
database.has(key) // Returns boolean
lookup
Lookup Data In The Database
Parameters
value
any
database.lookup(value) // Returns data
sort
Sort the database
Parameters
database.sort(key, reverse)
port
Port Json To The Database
Parameters
json
anyoverwrite
boolean
database.port(json, overwrite)
save
Save Database To:
localStorage node-fs
database.save()
load
Load Database From:
localStorage node-fs
Parameters
overwrite
boolean
let overwrite = false;
database.load(overwrite)
save
Save Database Backup To:
localStorage node-fs
database.saveBackup()
load
Load Database Backup From:
localStorage node-fs
Parameters
overwrite
boolean
let overwrite = false;
database.loadBackup(overwrite)
raw
Get Raw Database Data
database.raw() // Returns object
find
Find entry by query
database.find({name:"something",value:"something"}) // Returns entry
Parameters
findMultiple
Find one or more entries by query
database.findMultiple({name:"something",value:"something"}) //Returns an array of entries
Paramters
Boot
SuchDB
var options = {
master: "data",
autosave: true,
autoload: false,
encrypt: {
enabled: true,
key: "SuchDB_Key",
},
autobackup: true,
};
let database = new SuchDB.SuchDB(options);
let SuchDB = require("@sectly-studios/suchdb");
Parameters
options
Object
var options = {
master: "data",
autosave: true,
autoload: false,
encrypt: {
enabled: true,
key: "SuchDB_Key",
},
autobackup: true,
};