This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.js
73 lines (68 loc) · 1.71 KB
/
sql.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file Parent to all postgreSQL functions
* @author Daniel Breiner <danielbreinerd@gmail.com>
*/
const Client = require('pg').Client;
if(!process.env.moneasy){
var keys = require("./config/keys");
}
/**
* Main way to access the SQL database
*
* @param {string} query SQL query
* @param {function} cb Result callback; 1 parameter: result
* @param {function} onErr Error callback; 1 parameter: error
* @returns {void} This is a void function
*/
function query(query, cb, onErr) {
let client = new Client({
connectionString: process.env.DATABASE_URL || keys.postgres.connectionString,
ssl: true,
});
client.connect()
client.query(query)
.then((res) => {
if(cb) cb(res);
})
.catch((err) => {
if(onErr) onErr(err);
else throw err;
})
.then(() => { client.end(); })
}
module.exports = {
query: query
};
// const { Pool } = require('pg');
// function connect() {
// return new Pool({
// connectionString: process.env.DATABASE_URL || keys.postgres.connectionString,
// ssl: true,
// });
// }
// module.exports = {
// /**
// * @deprecated
// */
// connect: connect,
// /**
// * @deprecated
// */
// insert: require("./sql/insert.js")(connect),
// /**
// * @deprecated
// */
// request: require("./sql/request.js")(connect),
// /**
// * @deprecated
// */
// requestAll: require("./sql/requestAll.js")(connect),
// /**
// * @deprecated
// */
// requestRaw: require("./sql/requestRaw.js")(connect),
// /**
// * @deprecated
// */
// insertGoal: require("./sql/insertGoal.js")(connect)
// }