Another big refactoring
This commit is contained in:
parent
61b5c8493e
commit
68c457964a
10 changed files with 79 additions and 83 deletions
|
@ -1,20 +1,20 @@
|
|||
import db from './db.js';
|
||||
|
||||
const getTokenStatement = db.prepare(`SELECT value from config where key = 'token';`);
|
||||
const registerAgentStatement = db.prepare(`INSERT INTO config(key, value) VALUES ('symbol', ?), ('faction', ?), ('token', ?);`);
|
||||
const getTokenStatement = db.prepare(`SELECT json_extract(value, '$.token') as token from config where key = 'register_data';`);
|
||||
const registerAgentStatement = db.prepare(`INSERT INTO config(key, value) VALUES ('register_data', json(?));`);
|
||||
|
||||
export function getToken() {
|
||||
try {
|
||||
return getTokenStatement.get().value;
|
||||
return getTokenStatement.get().token;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function registerAgent(symbol, faction, token) {
|
||||
export function registerAgent(data) {
|
||||
try {
|
||||
registerAgentStatement.run(symbol, faction, token);
|
||||
registerAgentStatement.run(JSON.stringify(data));
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import db from './db.js';
|
||||
|
||||
const getSystemStatement = db.prepare(`SELECT data from systems where json_extract(data, '$.symbol') = ?;`);
|
||||
const getSystemUpdatedStatement = db.prepare(`SELECT updated from systems where json_extract(data, '$.symbol') = ?;`);
|
||||
const getSystemStatement = db.prepare(`SELECT data FROM systems WHERE json_extract(data, '$.symbol') = ?;`);
|
||||
const getSystemUpdatedStatement = db.prepare(`SELECT updated FROM systems WHERE json_extract(data, '$.symbol') = ?;`);
|
||||
const setSystemStatement = db.prepare(`INSERT INTO systems(data) VALUES (json(?));`);
|
||||
const setSystemWaypointsStatement = db.prepare(`UPDATE systems SET data = (SELECT json_set(data, '$.waypoints', json(:waypoints)) FROM systems WHERE json_extract(data, '$.symbol') = :symbol), updated = :date WHERE json_extract(data, '$.symbol') = :symbol;`);
|
||||
|
||||
|
@ -61,7 +61,7 @@ export function setSystemWaypoints(symbol, waypoints) {
|
|||
date: new Date().toISOString(),
|
||||
symbol: symbol,
|
||||
waypoints: JSON.stringify(waypoints),
|
||||
});
|
||||
}).changes;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue