-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
54 lines (50 loc) · 1.19 KB
/
database.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
45
46
47
48
49
50
51
52
53
54
const { Pool } = require('pg')
const pool = new Pool({
host: process.env.DATABASE_HOST || 'localhost',
user: process.env.DATABASE_USER || 'postgres',
database: process.env.DATABASE_NAME || 'vozativabot',
password: process.env.DATABASE_PASSWORD || 'secret',
max: 20,
idleTimeoutMillis: 0,
connectionTimeoutMillis: 2000,
ssl: true
});
const getAdmins = () => {
return new Promise((resolve, reject) => {
pool.connect((error, client, release) => {
if (error) {
reject(error);
} else {
client.query('SELECT * FROM admins', (error, results) => {
release();
if (error) {
reject(error.stack);
} else {
resolve(results);
}
})
}
})
})
}
const saveLog = (log) => {
return new Promise((resolve, reject) => {
pool.connect((error, client, release) => {
if (error) {
reject(error);
} else {
client.query('INSERT INTO logs (log) VALUES ($1)', [log], (error, results) => {
release();
if (error) {
reject(error);
}
resolve(results);
})
}
})
})
}
module.exports = {
getAdmins,
saveLog
}