Methods
() → {Number}
Returns either a number that is defined by a global generator for an ID or it will return a quasi random token that can be good for testing. It is best for an application to provide a method for generating IDs via the configuration.
Returns:
a number to use as an id
- Type
- Number
all_keys() → {Array}
Returns:
- a list of all the
_ids in the database and loaded into memory.
- Type
- Array
app_shutdown()
on shutdown, this method will be called in order to flush out the local tables (in this case JS Objects) to the file system./
create(obj, cb)
The object data is passed for inclusion into the DB.
If the object does not have an _id field, the method attempts to create one.
A call to create will not overwrite an existing object (user update).
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object | |
cb |
function | the callback will receive null if there is no error, otherwise, it will be passed an Error object. |
delete(id, cb)
Given the object is in the map, deletes it.
If the callback is provided, it will call it with an error if it is not found. The callback will be called with null if the object can be deleted.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | |
cb |
function |
findOne(id, cb) → {boolean|object}
Returns an object stored in the local application storage map.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | |
cb |
function |
Returns:
if ther eis no callback, returns the object found otherwise true and the object is passed to the callback
- Type
- boolean | object
initialize(conf)
Sets the path of the DB file, where data will be stored between runs. Setsup up an interval benchmark writing of the file to the directory.
Parameters:
| Name | Type | Description |
|---|---|---|
conf |
object |
update(obj, cb)
Overwrites the data of the object in the DB. The object must be in the DB, or this call will provide an error to the callback (if the callback is used)
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object | |
cb |
function |