first commit
This commit is contained in:
26
util/pg.js
Normal file
26
util/pg.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const Pool = require('pg-pool');
|
||||
|
||||
const pgConnection = new Pool({
|
||||
user: process.env.POSTGRESQL_USERNAME,
|
||||
password: process.env.POSTGRESQL_PASSWORD,
|
||||
host: process.env.POSTGRESQL_HOST,
|
||||
port: 5432,
|
||||
database: process.env.POSTGRESQL_DATABASE
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
pgQuery: async (sql, values) => {
|
||||
let connection = false
|
||||
try {
|
||||
connection = await pgConnection.connect()
|
||||
let results = await connection.query(sql, values)
|
||||
return results
|
||||
} catch (error) {
|
||||
throw error
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.release()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user