forked from Boomhuh/Qwakeactyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
30 lines (21 loc) · 799 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
const settings = require("./settings.json");
const db = require('better-sqlite3')(settings.database);
db.prepare(`CREATE TABLE IF NOT EXISTS "keyv" ("key" VARCHAR(255) PRIMARY KEY, "value" TEXT)`).run();
module.exports = {
async get(key) {
let row = await db.prepare('SELECT * FROM keyv WHERE key = ?').get(`keyv:${key}`);
return row ? JSON.parse(row.value).value : undefined;
},
async set(key, value) {
await this.delete(key);
await db.prepare('INSERT INTO keyv (key, value) VALUES (?, ?)').run(`keyv:${key}`, JSON.stringify({
value: value,
expires: null
}));
return true;
},
async delete(key) {
db.prepare('DELETE FROM keyv WHERE key=?').run(`keyv:${key}`);
return true;
}
};