summaryrefslogtreecommitdiff
path: root/nodejs/database/systems.js
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-27 15:20:14 +0100
committerJulien Dessaux2024-03-27 15:21:37 +0100
commita1d6b03ec98abbc073b5b73b631da6ea3eae4eb9 (patch)
tree1566c60bf1155e62821d9561ba1cc998b04b8ea5 /nodejs/database/systems.js
parent[all] fixed erroneous contracts index (diff)
downloadspacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.gz
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.bz2
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.zip
[node] finished the great typescript rewrite
Diffstat (limited to 'nodejs/database/systems.js')
-rw-r--r--nodejs/database/systems.js56
1 files changed, 0 insertions, 56 deletions
diff --git a/nodejs/database/systems.js b/nodejs/database/systems.js
deleted file mode 100644
index f989218..0000000
--- a/nodejs/database/systems.js
+++ /dev/null
@@ -1,56 +0,0 @@
-import db from './db.js';
-
-const addSystemStatement = db.prepare(`INSERT INTO systems(data) VALUES (json(?));`);
-const getSystemStatement = db.prepare(`SELECT data FROM systems WHERE data->>'symbol' = ?;`);
-const getSystemUpdatedStatement = db.prepare(`SELECT updated FROM systems WHERE data->>'symbol' = ?;`);
-const getSystemsCountStatement = db.prepare(`SELECT COUNT(data) as data FROM systems;`);
-const setSystemStatement = db.prepare(`UPDATE systems SET data = json(:data), updated = :date WHERE data->>'symbol' = :symbol;`);
-const setSystemWaypointsStatement = db.prepare(`UPDATE systems SET data = (SELECT json_set(data, '$.waypoints', json(:waypoints)) FROM systems WHERE data->>'symbol' = :symbol), updated = :date WHERE data->>'symbol' = :symbol;`);
-
-export function addSystem(data) {
- return addSystemStatement.run(JSON.stringify(data)).lastInsertRowid;
-}
-
-export function getSystem(symbol) {
- const data = getSystemStatement.get(symbol);
- if (data === undefined) {
- return null;
- }
- return JSON.parse(data.data);
-}
-
-export function getSystemsCount() {
- const data = getSystemsCountStatement.get();
- if (data === undefined) {
- return null;
- }
- return data.data;
-}
-
-export function getSystemUpdated(symbol) {
- const updated = getSystemUpdatedStatement.get(symbol);
- if (updated === undefined) {
- return null;
- }
- return updated.updated;
-}
-
-export function setSystem(data) {
- if (getSystem(data.symbol) === null) {
- addSystem(data);
- } else {
- return setSystemStatement.run({
- data: JSON.stringify(data),
- date: new Date().toISOString(),
- symbol: data.symbol,
- }).changes;
- }
-}
-
-export function setSystemWaypoints(symbol, waypoints) {
- return setSystemWaypointsStatement.run({
- date: new Date().toISOString(),
- symbol: symbol,
- waypoints: JSON.stringify(waypoints),
- }).changes;
-}