-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
32 lines (24 loc) · 781 Bytes
/
db.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
const Pool = require('pg-pool');
const url = require('url');
const params = url.parse(process.env.DATABASE_URL);
const auth = params.auth.split(':');
const config = {
user: auth[0],
password: auth[1],
host: params.hostname,
port: params.port,
database: params.pathname.split('/')[1],
ssl: false
};
const pool = new Pool(config);
pool.query('truncate tracker.user');
module.exports.query = (text, values) => {
return pool.query(text, values);
};
module.exports.checkSecret = (secret) => {
return pool.query('select * from tracker.user where secret = $1', [secret]);
};
module.exports.checkTorrent = (hash) => {
return pool.query('select * from tracker.torrents where hash = $1', [hash]);
};
module.exports.pg = pool.client;