fix: pg client logic

This commit is contained in:
NunoSempere 2022-02-12 16:13:51 -05:00
parent 29c51a13ed
commit 8b6f648c08

View File

@ -32,17 +32,18 @@ const readOnlyPool = new Pool({
// Helpers
const runPgCommand = async ({ command, pool }) => {
console.log(command)
try{
const client = await pool.connect();
const result = await client.query(command);
const results = { 'results': (result) ? result.rows : null };
}catch(error){
let result
try {
let response = await client.query(command);
result = { 'results': (response) ? response.rows : null };
} catch (error) {
console.log(error)
}finally{
} finally {
client.release();
}
// console.log(results)
return results
return result
}
// Initialize
@ -149,12 +150,13 @@ export async function pgInsert({ datum, schema, tableName }) {
JSON.stringify(datum.qualityindicators || []),
JSON.stringify(datum.extra || [])
]
try{
const client = await readWritePool.connect();
const result = await client.query(text, values);
}catch(error){
let result
try {
result = await client.query(text, values);
} catch (error) {
console.log(error)
}finally{
} finally {
client.release();
}
// console.log(result)