mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:37:07 +00:00
Refactor DB interface to use setSurvey()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 => [
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user