-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
28 lines (19 loc) · 972 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
const Database = require("better-sqlite3"),
db = new Database("tokens.db");
function getTokens(username) {
const query = db.prepare(`SELECT access_token, refresh_token FROM tokens WHERE username='${username}'`);
return query.get();
}
function addUser(username, access_token, refresh_token) {
const query = db.prepare(`INSERT INTO tokens (username, access_token, refresh_token) VALUES ('${username}', '${access_token}', '${refresh_token}')`);
return query.run();
}
function updateAccessToken(username, access_token) {
const query = db.prepare(`UPDATE tokens SET access_token='${access_token}' WHERE username='${username}'`);
return query.run();
}
function createTable() {
const query = db.prepare(`CREATE TABLE IF NOT EXISTS tokens (username TEXT, access_token TEXT, refresh_token TEXT);`);
return query.run();
}
module.exports = {getTokens: getTokens, addUser: addUser, updateAccessToken: updateAccessToken, createTable: createTable};