Database(system, cfgDir, defaults)

The class that manages the applications's main database

new Database(system, cfgDir, defaults)

Create a new application flat file DB controller
Parameters:
Name Type Description
system EventEmitter the application's event emitter
cfgDir string the directory the flat file will be saved
defaults Array.<Object> the default data to use when making a new file
Since:
  • 1.0.4
Author:

Extends

Members

protected debug :debug.Debugger

The debugger for this class

protected registry :Registry

the core registry

SaveInterval :number

The default minimum interval in ms to save to disk (4000 ms)

Methods

deleteKey(key)

Delete a key/value pair
Parameters:
Name Type Description
key string the key to be delete
Overrides:

getAll(cloneopt) → {Array.<Object>}

Get the entire database
Parameters:
Name Type Attributes Default Description
clone boolean <optional>
false `true` if a clone is needed instead of a link
Returns:
Array.<Object> - the database
Overrides:

getCfgDir() → {string}

Returns:
string - the directory of the flat file
Overrides:

getKey(key, defaultValuenullable, cloneopt)

Get a value from the database
Parameters:
Name Type Attributes Default Description
key string the key to be retrieved
defaultValue Array.<Object> <nullable>
the default value to use if the key doesn't exist
clone boolean <optional>
false `true` if a clone is needed instead of a link
Overrides:

protected load()

Attempt to load the database from disk
Overrides:

protected loadBackup(cfgBakFile)

Attempt to load the backup file from disk as a recovery
Parameters:
Name Type Description
cfgBakFile string the full file path
Overrides:

protected loadDefaults()

Save the defaults since a file could not be found/loaded/parses
Overrides:

protected save(withBackupopt)

Save the database to file
Parameters:
Name Type Attributes Default Description
withBackup boolean <optional>
true can be set to `false` if the current file should not be moved to `FILE.bak`
Overrides:

protected saveMain()

Save the database to file making a `FILE.bak` version then moving it into place
Overrides:

setDirty()

Register that there are changes in the database that need to be saved as soon as possible
Overrides:

setKey(key, value)

Save/update a key/value pair to the database
Parameters:
Name Type Description
key number | string the key to save under
value Object the object to save
Overrides:

setKeys(keyvalueobj)

Save/update multiple key/value pairs to the database
Parameters:
Name Type Description
keyvalueobj Array.<(number|string), Object> the key to save under
Overrides:

protected setSaveCycle()

Setup the save cycle interval
Overrides: