diff options
author | Julien Dessaux | 2023-06-17 01:46:44 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-06-17 01:46:44 +0200 |
commit | 0bc0df08914478612b1ccd4acd56f93454f7c91b (patch) | |
tree | 799a274018f794ca7fed521713cb43f69cae3baa /database | |
parent | Activate sqlite WAL (diff) | |
download | spacetraders-0bc0df08914478612b1ccd4acd56f93454f7c91b.tar.gz spacetraders-0bc0df08914478612b1ccd4acd56f93454f7c91b.tar.bz2 spacetraders-0bc0df08914478612b1ccd4acd56f93454f7c91b.zip |
Fixed prepared statements
Diffstat (limited to 'database')
-rw-r--r-- | database/systems.js | 6 |
1 files changed, 4 insertions, 2 deletions
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; } |