summaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
Diffstat (limited to 'database')
-rw-r--r--database/001_systems.sql6
-rw-r--r--database/db.js1
-rw-r--r--database/systems.js26
3 files changed, 33 insertions, 0 deletions
diff --git a/database/001_systems.sql b/database/001_systems.sql
new file mode 100644
index 0000000..8448955
--- /dev/null
+++ b/database/001_systems.sql
@@ -0,0 +1,6 @@
+CREATE TABLE systems (
+ id INTEGER PRIMARY KEY,
+ symbol TEXT NOT NULL UNIQUE,
+ data TEXT NOT NULL,
+ updated DATE DEFAULT (datetime('now'))
+);
diff --git a/database/db.js b/database/db.js
index db71080..6deddcc 100644
--- a/database/db.js
+++ b/database/db.js
@@ -3,6 +3,7 @@ import Database from 'better-sqlite3';
const allMigrations = [
'database/000_init.sql',
+ 'database/001_systems.sql',
];
const db = new Database(
diff --git a/database/systems.js b/database/systems.js
new file mode 100644
index 0000000..46b4663
--- /dev/null
+++ b/database/systems.js
@@ -0,0 +1,26 @@
+import db from './db.js';
+
+const getSystemStatement = db.prepare(`SELECT data from systems where symbol = ?;`);
+const setSystemStatement = db.prepare(`INSERT INTO systems(symbol, data) VALUES (?, ?);`);
+
+export function getSystem(symbol) {
+ try {
+ const data = getSystemStatement.get(symbol);
+ if (data === undefined) {
+ return null;
+ }
+ return JSON.parse(data.data);
+ } catch (err) {
+ console.log(err);
+ return null;
+ }
+}
+
+export function setSystem(symbol, data) {
+ try {
+ return setSystemStatement.run(symbol, JSON.stringify(data)).lastInsertRowid;
+ } catch (err) {
+ console.log(err);
+ return null;
+ }
+}