summaryrefslogtreecommitdiff
path: root/nodejs/database
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--nodejs/database/ships.ts7
1 files changed, 6 insertions, 1 deletions
diff --git a/nodejs/database/ships.ts b/nodejs/database/ships.ts
index 5ea2ffa..c827db8 100644
--- a/nodejs/database/ships.ts
+++ b/nodejs/database/ships.ts
@@ -5,6 +5,7 @@ import { Fuel, Nav, Ship } from '../model/ship.ts';
const addShipStatement = db.prepare(`INSERT INTO ships(data) VALUES (json(?));`);
const getShipStatement = db.prepare(`SELECT data FROM ships WHERE data->>'symbol' = ?;`);
const getShipsAtStatement = db.prepare(`SELECT data FROM ships WHERE data->>'$.nav.systemSymbol' = ?;`);
+const getShipsStatement = db.prepare(`SELECT data FROM ships;`);
const setShipCargoStatement = db.prepare(`UPDATE ships SET data = (SELECT json_set(data, '$.cargo', json(:cargo)) FROM ships WHERE data->>'symbol' = :symbol) WHERE data->>'symbol' = :symbol;`);
const setShipFuelStatement = db.prepare(`UPDATE ships SET data = (SELECT json_set(data, '$.fuel', json(:fuel)) FROM ships WHERE data->>'symbol' = :symbol) WHERE data->>'symbol' = :symbol;`);
const setShipNavStatement = db.prepare(`UPDATE ships SET data = (SELECT json_set(data, '$.nav', json(:nav)) FROM ships WHERE data->>'symbol' = :symbol) WHERE data->>'symbol' = :symbol;`);
@@ -16,12 +17,16 @@ export function getShip(symbol: string): Ship {
return JSON.parse(data.data);
}
+export function getShips(): Array<Ship> {
+ const data = getShipsStatement.all() as Array<DbData>;
+ return data.map(elt => JSON.parse(elt.data));
+}
+
export function getShipsAt(symbol: string): Array<Ship> {
const data = getShipsAtStatement.all(symbol) as Array<DbData>;
return data.map(elt => JSON.parse(elt.data));
}
-
export function setShip(data: Ship): void {
const changes = updateShipStatement.run({
data: JSON.stringify(data),