fix: pg client logic
This commit is contained in:
parent
29c51a13ed
commit
8b6f648c08
|
@ -12,7 +12,7 @@ const tableWhiteList = [...createFullName("latest", tableNamesWhitelist), ...cre
|
||||||
|
|
||||||
|
|
||||||
/* Postgres database connection code */
|
/* Postgres database connection code */
|
||||||
const databaseURL = process.env.DIGITALOCEAN_POSTGRES || getSecret("digitalocean-postgres")
|
const databaseURL = process.env.DIGITALOCEAN_POSTGRES || getSecret("digitalocean-postgres")
|
||||||
// process.env.DATABASE_URL || getSecret("heroku-postgres")
|
// process.env.DATABASE_URL || getSecret("heroku-postgres")
|
||||||
const readWritePool = new Pool({
|
const readWritePool = new Pool({
|
||||||
connectionString: databaseURL,
|
connectionString: databaseURL,
|
||||||
|
@ -32,17 +32,18 @@ const readOnlyPool = new Pool({
|
||||||
// Helpers
|
// Helpers
|
||||||
const runPgCommand = async ({ command, pool }) => {
|
const runPgCommand = async ({ command, pool }) => {
|
||||||
console.log(command)
|
console.log(command)
|
||||||
try{
|
const client = await pool.connect();
|
||||||
const client = await pool.connect();
|
let result
|
||||||
const result = await client.query(command);
|
try {
|
||||||
const results = { 'results': (result) ? result.rows : null };
|
let response = await client.query(command);
|
||||||
}catch(error){
|
result = { 'results': (response) ? response.rows : null };
|
||||||
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}finally{
|
} finally {
|
||||||
client.release();
|
client.release();
|
||||||
}
|
}
|
||||||
// console.log(results)
|
// console.log(results)
|
||||||
return results
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
|
@ -149,12 +150,13 @@ export async function pgInsert({ datum, schema, tableName }) {
|
||||||
JSON.stringify(datum.qualityindicators || []),
|
JSON.stringify(datum.qualityindicators || []),
|
||||||
JSON.stringify(datum.extra || [])
|
JSON.stringify(datum.extra || [])
|
||||||
]
|
]
|
||||||
try{
|
const client = await readWritePool.connect();
|
||||||
const client = await readWritePool.connect();
|
let result
|
||||||
const result = await client.query(text, values);
|
try {
|
||||||
}catch(error){
|
result = await client.query(text, values);
|
||||||
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}finally{
|
} finally {
|
||||||
client.release();
|
client.release();
|
||||||
}
|
}
|
||||||
// console.log(result)
|
// console.log(result)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user