From 0bc0df08914478612b1ccd4acd56f93454f7c91b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 17 Jun 2023 01:46:44 +0200 Subject: Fixed prepared statements --- database/systems.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'database') diff --git a/database/systems.js b/database/systems.js index 479deb6..0d637df 100644 --- a/database/systems.js +++ b/database/systems.js @@ -2,12 +2,14 @@ import db from './db.js'; const getSystemStatement = db.prepare(`SELECT data FROM systems WHERE data->>'symbol' = ?;`); const getSystemUpdatedStatement = db.prepare(`SELECT updated FROM systems WHERE data->>'symbol' = ?;`); +const initStatement = db.prepare(`INSERT INTO config(key, value) VALUES ('systems_initialized', TRUE);`); +const isInitStatement = db.prepare(`SELECT value FROM config WHERE key = 'systems_initialized'`); 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 data->>'symbol' = :symbol), updated = :date WHERE data->>'symbol' = :symbol;`); export function init() { try { - return db.prepare(`INSERT INTO config(key, value) VALUES ('systems_initialized', TRUE);`).run().lastInsertRowid; + return initStatement.run().lastInsertRowid; } catch (err) { return null; } @@ -15,7 +17,7 @@ export function init() { export function isInit() { try { - return db.prepare(`SELECT value FROM config WHERE key = 'systems_initialized'`).get().value === '1'; + return isInitStatement.get().value === '1'; } catch (err) { return false; } -- cgit v1.2.3