abstract DataStoreBase(system, name, cfgDir, saveInterval, defaults)

Abstract class to be extended by the flat file DB classes. See Config and Database

new abstract DataStoreBase(system, name, cfgDir, saveInterval, defaults)

Create a new flat file DB controller
Parameters:
Name Type Description
system EventEmitter the application's event emitter
name string the name of the flat file
cfgDir string the directory the flat file will be saved
saveInterval number minimum interval in ms to save to disk
defaults Array.<Object> the default data to use when making a new file
Since:
  • 2.2.0
Author:

Methods

deleteKey(key)

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

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

getCfgDir() → {string}

Returns:
string - the directory of the flat file

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

protected load()

Attempt to load the database from disk

protected loadBackup(cfgBakFile)

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

protected loadDefaults()

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

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`

protected saveMain()

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

setDirty()

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

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

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

protected setSaveCycle()

Setup the save cycle interval