Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sql querys for create-contour worker #232

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/create-contour/add-to-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const addData = async (
const timestamp = process.argv[2] ?? datasetTimestamp;
const geom = process.argv[2] ?? contourLine.geometry;
const temp = process.argv[2] ?? contourLine.properties.TEMP;
let insertRow = await client.query(`INSERT INTO ${region}_contourLines(timestamp, geom, temp) VALUES($1);`, [timestamp, geom, temp]);
let insertRow = await client.query(`INSERT INTO ${region}_contourLines(timestamp, geom, temperature) VALUES(${timestamp}, ${geom}, ${temp});`);
logger.info(`Inserted ${insertRow.rowCount} row`);
} catch (e) {
logger.error(e);
Expand Down
5 changes: 1 addition & 4 deletions src/create-contour/get-client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Connect to databse

import pkg from 'pg';
const { Client } = pkg
import dotenv from 'dotenv'
dotenv.config();
const { Client } = pkg;

const pgHost = process.env.POSTGRES_HOST;
const pgPort = process.env.POSTGRES_PORT;
Expand Down
14 changes: 6 additions & 8 deletions src/create-contour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ const contourLinesWorker = async (workerJob, inputs) => {
// TODO check if this can be moved to seperate file
let client;
try {
(async () => {
client = await getClient();
let createTableQuery = `
client = await getClient();
let createTableQuery = `
CREATE TABLE IF NOT EXISTS ${region}_contourLines(
id BIGSERIAL PRIMARY KEY NOT NULL ,
timestamp timestamp without timezone,
timestamp timestamp,
geom geometry,
temp number,
temperature numeric
);
`;
await client.query(createTableQuery);
logger.info(`Created table.`);
})();
await client.query(createTableQuery);
logger.info(`Created table.`);
} catch (e) {
logger.error(e);
throw 'SQL execution aborted: ' + e;
Expand Down
12 changes: 0 additions & 12 deletions src/create-contour/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/create-contour/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"dependencies": {
"amqplib": "^0.8.0",
"dayjs": "^1.11.10",
"dotenv": "^16.4.1",
"fs": "^0.0.1-security",
"node": "^21.6.1",
"pg": "^8.11.3",
Expand Down
Loading