forked from xhackjp1/line-messaging-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresManager.js
53 lines (46 loc) · 1.08 KB
/
postgresManager.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
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
client.connect(function(err) {
if (err) {
return console.error('could not connect to postgres', err);
}
});
exports.get_words = function(callback) {
var query = `select id, word from words;`;
client.query(
query,
function(err, result) {
if (err) {
return console.error('error running query', err);
}
callback(result);
}
);
}
exports.add_word = function(message, callback) {
var query = `insert into words (id, word) values ((select max(id) from words) + 1, '${message}');`;
client.query(
query,
function(err, result) {
if (err) {
return console.error('error running query', err);
}
callback(result);
}
);
}
exports.delete_word = function(id, callback) {
var query = `delete from words where id = ${id};`;
client.query(
query,
function(err, result) {
if (err) {
return console.error('error running query', err);
}
callback(result);
}
);
}