diff --git a/lib/www/server/lib/db/configuration.js b/lib/www/server/lib/db/configuration.js index 62ef93d..acb17fa 100644 --- a/lib/www/server/lib/db/configuration.js +++ b/lib/www/server/lib/db/configuration.js @@ -1,7 +1,7 @@ -const { pool } = require('./connection'); +const { setSurvey } = require('./connection'); async function get (projectId, path, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const text = ` SELECT data @@ -10,7 +10,8 @@ async function get (projectId, path, opts = {}) { WHERE f.path LIKE '%.yaml'; `; - const res = await pool.query(text); + const res = await client.query(text); + client.release(); const config = res.rows.length == 1 ? res.rows[0].data diff --git a/lib/www/server/lib/db/event/list.js b/lib/www/server/lib/db/event/list.js index e78b988..fcea396 100644 --- a/lib/www/server/lib/db/event/list.js +++ b/lib/www/server/lib/db/event/list.js @@ -1,7 +1,7 @@ -const { pool } = require('../connection'); +const { setSurvey } = require('../connection'); async function list (projectId, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const sortFields = [ "sequence", "shot_number", "ts0", "ts1", "label", "remarks" ]; const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "ts0"; @@ -27,7 +27,8 @@ async function list (projectId, opts = {}) { ORDER BY ${sortKey} ${sortDir}; `; - const res = await pool.query(text, filter[1]); + const res = await client.query(text, filter[1]); + client.release(); return res.rows; } diff --git a/lib/www/server/lib/db/gis/project/bbox.js b/lib/www/server/lib/db/gis/project/bbox.js index 6bfa89c..2952879 100644 --- a/lib/www/server/lib/db/gis/project/bbox.js +++ b/lib/www/server/lib/db/gis/project/bbox.js @@ -1,14 +1,15 @@ -const { pool } = require('../../connection'); +const { setSurvey } = require('../../connection'); async function bbox (projectId) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const srid = "(SELECT ST_SRID(geometry) FROM preplot_lines LIMIT 1)" const text = `SELECT ST_AsGeoJSON(ST_Transform(ST_SetSRID(ST_Extent(geometry), ${srid}), 4326)) AS bbox FROM preplot_lines;` - const res = await pool.query(text); + const res = await client.query(text); + client.release(); if (res.rows && res.rows.length) { return res.rows[0].bbox; } else { diff --git a/lib/www/server/lib/db/gis/project/final.js b/lib/www/server/lib/db/gis/project/final.js index 038d551..16f7835 100644 --- a/lib/www/server/lib/db/gis/project/final.js +++ b/lib/www/server/lib/db/gis/project/final.js @@ -1,10 +1,10 @@ -const { pool } = require('../../connection'); +const { setSurvey } = require('../../connection'); async function lines (projectId) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const text = ` SELECT ST_AsGeoJSON(s.*) geojson @@ -15,7 +15,8 @@ async function lines (projectId) { ) s; `; - const res = await pool.query(text); + const res = await client.query(text); + client.release(); if (res.rows && res.rows.length) { return res.rows.map(r => JSON.parse(r.geojson)); @@ -26,7 +27,7 @@ async function lines (projectId) { async function points (projectId, options = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const values = [ "bbox" in options, @@ -49,7 +50,8 @@ async function points (projectId, options = {}) { ) t `; - const res = await pool.query(text, values); + const res = await client.query(text, values); + client.release(); if (res.rows && res.rows.length) { return res.rows.map(r => JSON.parse(r.geojson)); diff --git a/lib/www/server/lib/db/gis/project/preplot.js b/lib/www/server/lib/db/gis/project/preplot.js index 06f2094..cdd5cd8 100644 --- a/lib/www/server/lib/db/gis/project/preplot.js +++ b/lib/www/server/lib/db/gis/project/preplot.js @@ -1,9 +1,9 @@ -const { pool } = require('../../connection'); +const { setSurvey } = require('../../connection'); async function lines (projectId, options = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const values = [ "bbox" in options, @@ -34,7 +34,8 @@ async function lines (projectId, options = {}) { ) f; `; - const res = await pool.query(text, values); + const res = await client.query(text, values); + client.release(); if (res.rows && res.rows.length) { return res.rows[0].geojson; @@ -45,7 +46,7 @@ async function lines (projectId, options = {}) { async function points (projectId, options = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const values = [ "bbox" in options, @@ -76,7 +77,8 @@ async function points (projectId, options = {}) { ) f; `; - const res = await pool.query(text, values); + const res = await client.query(text, values); + client.release(); if (res.rows && res.rows.length) { return res.rows[0].geojson; diff --git a/lib/www/server/lib/db/gis/project/raw.js b/lib/www/server/lib/db/gis/project/raw.js index af6746a..1ec5b50 100644 --- a/lib/www/server/lib/db/gis/project/raw.js +++ b/lib/www/server/lib/db/gis/project/raw.js @@ -1,10 +1,10 @@ -const { pool } = require('../../connection'); +const { setSurvey } = require('../../connection'); async function lines (projectId, options = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const text = ` SELECT ST_AsGeoJSON(s.*) geojson @@ -16,7 +16,8 @@ async function lines (projectId, options = {}) { `; - const res = await pool.query(text); + const res = await client.query(text); + client.release(); if (res.rows && res.rows.length) { return res.rows.map(r => JSON.parse(r.geojson)); @@ -27,7 +28,7 @@ async function lines (projectId, options = {}) { async function points (projectId, options = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const values = [ "bbox" in options, @@ -52,7 +53,8 @@ async function points (projectId, options = {}) { ) t `; - const res = await pool.query(text, values); + const res = await client.query(text, values); + client.release(); if (res.rows && res.rows.length) { return res.rows.map(r => [ diff --git a/lib/www/server/lib/db/label/list.js b/lib/www/server/lib/db/label/list.js index 050530b..c0595f6 100644 --- a/lib/www/server/lib/db/label/list.js +++ b/lib/www/server/lib/db/label/list.js @@ -1,7 +1,7 @@ -const { pool } = require('../connection'); +const { setSurvey } = require('../connection'); async function list (projectId, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const text = ` SELECT * @@ -9,7 +9,8 @@ async function list (projectId, opts = {}) { ORDER BY name; `; - const res = await pool.query(text); + const res = await client.query(text); + client.release(); return res.rows; } diff --git a/lib/www/server/lib/db/line.js b/lib/www/server/lib/db/line.js index 41bd2e3..675462f 100644 --- a/lib/www/server/lib/db/line.js +++ b/lib/www/server/lib/db/line.js @@ -1,7 +1,7 @@ -const { pool } = require('./connection'); +const { setSurvey } = require('./connection'); async function list (projectId, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const sortFields = [ "line", "length", "azimuth", "fsp", "lsp", "num_points", "incr", "remarks" ]; const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "line"; @@ -37,7 +37,8 @@ async function list (projectId, opts = {}) { LIMIT $2; `; - const res = await pool.query(text, [offset, limit]); + const res = await client.query(text, [offset, limit]); + client.release(); return res.rows; } diff --git a/lib/www/server/lib/db/project.js b/lib/www/server/lib/db/project.js index d57cb4a..a2c48b7 100644 --- a/lib/www/server/lib/db/project.js +++ b/lib/www/server/lib/db/project.js @@ -1,4 +1,4 @@ -const { pool } = require('./connection'); +const { setSurvey, pool } = require('./connection'); async function list () { const res = await pool.query("SELECT * FROM public.projects;"); @@ -6,7 +6,7 @@ async function list () { } async function summary (projectId, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const sortFields = [ @@ -32,7 +32,8 @@ SELECT * FROM projects, WHERE current_setting('search_path') LIKE projects.schema||'%'; `; - const res = await pool.query(text); + const res = await client.query(text); + client.release(); return res.rows[0]; } diff --git a/lib/www/server/lib/db/sequence.js b/lib/www/server/lib/db/sequence.js index 4ce1bc1..6e998e4 100644 --- a/lib/www/server/lib/db/sequence.js +++ b/lib/www/server/lib/db/sequence.js @@ -1,7 +1,7 @@ -const { pool } = require('./connection'); +const { setSurvey } = require('./connection'); async function list (projectId, opts = {}) { - await pool.query("CALL set_survey($1);", [projectId]); + const client = await setSurvey(projectId); const sortFields = [ "sequence", "line", "length", "azimuth", "fsp", "lsp", @@ -20,9 +20,8 @@ async function list (projectId, opts = {}) { LIMIT $2; `; - const res = await pool.query(text, [offset, limit]); - console.log(text, [offset, limit]); - console.log(opts); + const res = await client.query(text, [offset, limit]); + client.release(); return res.rows; }