-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg.js
More file actions
34 lines (31 loc) · 809 Bytes
/
pg.js
File metadata and controls
34 lines (31 loc) · 809 Bytes
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
const {Pool} = require("pg")
//const util = require("util")
const poolPg = new Pool({
host: '37.60.236.174',
user: 'postgres',
password: '1234',
database: 'postgres',
port: 5437
})
async function q(sql, parametros){
return new Promise(async (resolve, reject) => {
poolPg.connect((err, client, done) => {
if (err) reject(err)
client.query(sql, parametros, (err, result) => {
done()
if (err){
reject(err)
} else {
resolve(result.rows)
}
})
})
})
}
q("select * from Customers limit 2", []).then(rows =>{
console.log(rows)
}).catch(err => {
console.log(err)
}).finally(()=> {
console.log("this appears always")
})