Add pid2schema function.

Translates a project ID into a database schema name.
This commit is contained in:
D. Berge
2023-08-21 14:31:23 +02:00
parent 7cb2c3ef49
commit 44ad59130f

View File

@@ -49,6 +49,15 @@ async function schema2pid (schema, client) {
return res.rows[0] && res.rows[0].pid;;
}
async function pid2schema (pid, client) {
if (!client) {
client = await pool.connect();
}
const res = await client.query("SELECT schema FROM projects WHERE pid = $1", [pid]);
client.release();
return res.rows[0] && res.rows[0].schema;
}
/** Fetch one row from a database cursor.
*
* @a cursor A query cursor
@@ -75,5 +84,6 @@ module.exports = {
transaction,
setSurvey,
schema2pid,
pid2schema,
fetchRow
};