dbb
An easy to use database.
Example
var DBB = ;var db = ; ;;
In db.json
:
"keys": "key": "value" "posts": "_id": "851e4d6-df24-42fb-b478-4a0c93d117e1" "title": "DBB is amazing"
To query the data:
;;
Table of Contents ## Installation
$ npm install dbb --save
DBB stores data in a field which can be either be an object or an array.
"field": {} "field":
get
and set
method are for a document, also called an object.
// document"field": "key": "value" "key1": 1 "key2": 2
find
, insert
, and save are for a collection, which is basically an array.
// collection"field": _id: "89cbfd78-8ec8-4338-8140-7a3efa5e89c6" name: "phil" age: 7 _id: "12f3af49-b2e8-4e60-ae1c-9fb259ae6670" name: "jack" age: 20 _id: "6f33c2bd-7bbf-4b4d-a8e6-1973a3fa4f63" name: "steve" age: 99
For each DBB's method, there is a synchronous version of it. For example, get
and getSync
or find
and findSync
.
Documents
Collections ### Create Database
;
Specify what JSON file to use. If it doesn't exist, the JSON file will be created.
Arguments
file
(String): JSON file name.options
(Object): Provide options for DBB to used. Currently, there is only one option which isbackup
. The backup creates a POST request to Hastebin and adds the link to the DBB_BACKUPS field. You can set how long every hour the backup should save.
Examples
var DBB = ;var db = ;// create a back up every 4 hours;
Arguments
field
(String): Specify what field to query.
Returns
(Object): Methods to use to query the database.
Examples
; // default;; // converts to array
In json:
"default": {} "users": {} "posts": "title": "hello world!"
Documents ### get(key, [callback])
Get a key from the database.
Arguments
key
(String): Name of the key.callback(err, value)
(Function): A callback which is called when reading the JSON file has finished, or an error occurs. Value is the key's value.
Examples
;
Synchronous key
.
Arguments
key
(String): Name of the key.
Returns
(*): Key's value
Examples
var key = ;// do something with key
Get the whole object in the database.
Arguments
callback(err, object)
(Function): A callback which is called when reading the JSON file has finished, or an error occurs.
Examples
;
Get the whole object in the database.
Arguments
callback(err, object)
(Function): A callback which is called when reading the JSON file has finished, or an error occurs.
Returns
(Object): Object in the database that holds all the key-value pairs.
Examples
var object = ;// do something with object
Set a key with a value in the database.
Arguments
key
(String): Name of the key.value
(*): Value of the key.callback(err)
(Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.
Examples
;
Synchronous set
. Returns undefined.
Arguments
key
(String): Name of the key.value
(*): Value of the key. the JSON file has finished, or an error occurs. Value is the key's value.
Examples
;
Collections ### find(document, [callback])
Find a document (object) in the database.
Arguments
document
(Object): Document also known as a object.callback(err, doc)
(Function): A callback which is called when reading to the JSON file has finished, or an error occurs. Doc is the document (object).
Examples
;
Synchronous find
.
Arguments
document
(Object): Document also known as a object.
Returns
(Object): Document.
Examples
var phil = ;
Get the whole collection in the database.
Arguments
callback(err, docs)
(Function): A callback which is called when reading to the JSON file has finished, or an error occurs. Docs is an array.
Examples
;
Synchronous findAll
.
Returns
(Array): Collection of docs.
Examples
var docs = ;
Insert a document (object) into the database.
Arguments
document
(Object): Document also known as a object.callback(err, doc)
(Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs. Doc is the document inserted.
Examples
;
Synchronous insert
. Returns undefined.
Arguments
document
(Object): Document also known as a object.
Examples
;
Remove a key in the database.
Arguments
key
(String): Name of the key.callback(err)
(Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.
Examples
;;
Synchronous sync
. Returns undefined.
Arguments
key
(String): Name of the key.
Examples
;;
Save a document in the database.
Arguments
document
(*): Usually an object.callback(err)
(Function): Optional A callback which is called when writing to the JSON file has finished, or an error occurs.
Examples
;
Synchronous save
. Returns undefined.
Arguments
document
(*): Usually an object.
Examples
var user = ;username = 'jack';;
DBB is a convenient method for storing data without setting up a database server. However, if you need high performance and scalability more than simplicity, you should stick to databases like MongoDB.
## License