-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgsql.js
44 lines (43 loc) · 1.05 KB
/
pgsql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require("fs")
require('dotenv').config()
const { Pool } = require('pg')
let config = {
user: process.env.PGUSER,
host: 'localhost',
database: process.env.PGDATABASE,
password: process.env.PGPASSWORD,
port: process.env.PGPORT,
}
if(process.env.NODE_ENV==="PRODUCTION"){
config = {
user: process.env.PGUSER,
host: process.env.PGHOST,
database: process.env.PGDATABASE,
password: process.env.PGPASSWORD,
port: process.env.PGPORT,
ssl: {
rejectUnauthorized: false,
ca: fs.readFileSync('server-ca.pem').toString(),
key: fs.readFileSync('client-key.pem').toString(),
cert: fs.readFileSync('client-cert.pem').toString(),
},
}
}
console.log(config)
const pool = new Pool(config)
console.log(pool)
pool.query("SELECT * FROM users").then((result)=>{
console.log(result.rows)
})
module.exports = {
query: (text, params, callback) => {
try {
return pool.query(text, params, callback)
}
catch(e){
console.error(text,params)
console.error(e)
return e
}
},
}