From 3cb4f4df51059919b292fefb5f7a3e1ad99c9a91 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 28 Mar 2024 12:11:36 +0100 Subject: [node] stop trying to optimize useless things like local database calls --- nodejs/database/contracts.ts | 4 ++-- nodejs/database/ships.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'nodejs/database') 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); } -- cgit v1.2.3