From ecbe4d38ca084eebf6a061f67db3ddee3c7fa19b Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 16 Aug 2020 10:16:08 +0200 Subject: [PATCH] Add setSurvey() utility function to DB interface. It sets the current survey and optionally returns a client connection to use in subsequent queries. --- lib/www/server/lib/db/connection.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/www/server/lib/db/connection.js b/lib/www/server/lib/db/connection.js index adf4d21..3cf4d5c 100644 --- a/lib/www/server/lib/db/connection.js +++ b/lib/www/server/lib/db/connection.js @@ -28,7 +28,16 @@ const transaction = { } }; +async function setSurvey (projectId, client) { + if (!client) { + client = await pool.connect(); + } + await client.query("CALL set_survey($1);", [projectId]); + return client; +} + module.exports = { pool, transaction, + setSurvey };