summaryrefslogtreecommitdiff
path: root/nodejs/database
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-28 12:11:36 +0100
committerJulien Dessaux2024-03-28 12:11:36 +0100
commit3cb4f4df51059919b292fefb5f7a3e1ad99c9a91 (patch)
treebf97a8bdea32985f4c1a95e3759d5044b398789d /nodejs/database
parent[node] finished the great typescript rewrite (diff)
downloadspacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.tar.gz
spacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.tar.bz2
spacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.zip
[node] stop trying to optimize useless things like local database calls
Diffstat (limited to '')
-rw-r--r--nodejs/database/contracts.ts4
-rw-r--r--nodejs/database/ships.ts4
2 files changed, 4 insertions, 4 deletions
diff --git a/nodejs/database/contracts.ts b/nodejs/database/contracts.ts
index ff24524..8442622 100644
--- a/nodejs/database/contracts.ts
+++ b/nodejs/database/contracts.ts
@@ -6,9 +6,9 @@ const getContractStatement = db.prepare(`SELECT data FROM contracts WHERE data->
const getContractsStatement = db.prepare(`SELECT data FROM contracts WHERE data->>'fulfilled' = false;`);
const updateContractStatement = db.prepare(`UPDATE contracts SET data = json(:data) WHERE data->>'id' = :id;`);
-export function getContract(id: string): Contract|null {
+export function getContract(id: string): Contract {
const data = getContractStatement.get(id) as DbData|undefined;
- if (!data) return null;
+ if (!data) throw `invalid id ${id} in getContract database call`;
return JSON.parse(data.data);
}
diff --git a/nodejs/database/ships.ts b/nodejs/database/ships.ts
index 414a059..f918099 100644
--- a/nodejs/database/ships.ts
+++ b/nodejs/database/ships.ts
@@ -10,9 +10,9 @@ const setShipFuelStatement = db.prepare(`UPDATE ships SET data = (SELECT json_se
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;`);
const updateShipStatement = db.prepare(`UPDATE ships SET data = json(:data) WHERE data->>'symbol' = :symbol;`);
-export function getShip(symbol: string): Ship|null {
+export function getShip(symbol: string): Ship {
const data = getShipStatement.get(symbol) as DbData|undefined;
- if (!data) return null;
+ if (!data) throw `invalid symbol ${symbol} in getShip database call`;
return JSON.parse(data.data);
}