forked from Votion-Development/Dashactyl-0.4
-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
31 lines (22 loc) · 887 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
// This file was specifically created to support past Dashactyl versions that used keyv.
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;
}
};