From d9ee2b6c8056ef20db3bec9f9dd55fd00baa0a70 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 17 Oct 2015 20:56:16 -0600 Subject: [PATCH] * Add system_property.js --- core/system_property.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 core/system_property.js 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]; +}