1
0
Fork 0

Rewrote the api rate limiter with promises instead of callbacks

This commit is contained in:
Julien Dessaux 2023-05-24 23:03:19 +02:00
parent efdf50a55a
commit 9963ab79b7
Signed by: adyxax
GPG key ID: F92E51B86E07177E
6 changed files with 105 additions and 40 deletions

26
database/systems.js Normal file
View file

@ -0,0 +1,26 @@
import db from './db.js';
const getSystemStatement = db.prepare(`SELECT data from systems where symbol = ?;`);
const setSystemStatement = db.prepare(`INSERT INTO systems(symbol, data) VALUES (?, ?);`);
export function getSystem(symbol) {
try {
const data = getSystemStatement.get(symbol);
if (data === undefined) {
return null;
}
return JSON.parse(data.data);
} catch (err) {
console.log(err);
return null;
}
}
export function setSystem(symbol, data) {
try {
return setSystemStatement.run(symbol, JSON.stringify(data)).lastInsertRowid;
} catch (err) {
console.log(err);
return null;
}
}