mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
31 lines
677 B
JavaScript
31 lines
677 B
JavaScript
const { setSurvey } = require('../connection');
|
|
|
|
async function get (projectId, path, opts = {}) {
|
|
const client = await setSurvey(projectId);
|
|
const [key, ...subkey] = path.split("/");
|
|
|
|
const text = `
|
|
SELECT value
|
|
FROM info
|
|
WHERE key = $1;
|
|
`;
|
|
|
|
console.log("k, sk", key, subkey);
|
|
const res = await client.query(text, [key]);
|
|
client.release();
|
|
|
|
const value = res.rows[0] && res.rows[0].value;
|
|
|
|
if (subkey.length) {
|
|
console.log("Reducing value");
|
|
const res = subkey.reduce( (obj, idx) => typeof obj != "undefined" ? obj[idx] : obj, value);
|
|
console.log(res);
|
|
return res;
|
|
} else {
|
|
console.log("Returning value");
|
|
return value;
|
|
}
|
|
}
|
|
|
|
module.exports = get;
|