diff --git a/core/system_property.js b/core/system_property.js new file mode 100644 index 00000000..87f4f4fa --- /dev/null +++ b/core/system_property.js @@ -0,0 +1,38 @@ +/* jslint node: true */ +'use strict'; + +var sysDb = require('./database.js').dbs.system; + +exports.loadSystemProperties = loadSystemProperties; +exports.persistSystemProperty = persistSystemProperty; +exports.getSystemProperty = getSystemProperty; + +var systemProperties = {}; +exports.systemProperties = systemProperties; + +function loadSystemProperties(cb) { + sysDb.each( + 'SELECT prop_name, prop_value ' + + 'FROM system_property;', + function rowResult(err, row) { + systemProperties[row.prop_name] = row.prop_value; + }, + cb + ); +} + +function persistSystemProperty(propName, propValue, cb) { + // update live + systemProperties[propName] = propValue; + + sysDb.run( + 'REPLACE INTO system_property ' + + 'VALUES (?, ?);', + [ propName, propValue ], + cb + ); +} + +function getSystemProperty(propName) { + return systemProperties[propName]; +}