summaryrefslogtreecommitdiff
path: root/nodejs/database/contracts.js
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-21 17:08:37 +0100
committerJulien Dessaux2024-03-27 15:21:00 +0100
commitd668eac4a63a9aa98c3efff395faa23cfcea1c1b (patch)
tree691e3bb471bcacadb975f581f73e09b84287b4a5 /nodejs/database/contracts.js
parent[javascript] fixed mining loop (diff)
downloadspacetraders-d668eac4a63a9aa98c3efff395faa23cfcea1c1b.tar.gz
spacetraders-d668eac4a63a9aa98c3efff395faa23cfcea1c1b.tar.bz2
spacetraders-d668eac4a63a9aa98c3efff395faa23cfcea1c1b.zip
[node] begin the great typescript rewrite
Diffstat (limited to 'nodejs/database/contracts.js')
-rw-r--r--nodejs/database/contracts.js30
1 files changed, 0 insertions, 30 deletions
diff --git a/nodejs/database/contracts.js b/nodejs/database/contracts.js
deleted file mode 100644
index d7f9aab..0000000
--- a/nodejs/database/contracts.js
+++ /dev/null
@@ -1,30 +0,0 @@
-import db from './db.js';
-
-const addContractStatement = db.prepare(`INSERT INTO contracts(data) VALUES (json(?));`);
-const getContractStatement = db.prepare(`SELECT data FROM contracts WHERE data->>'id' = ?;`);
-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) {
- const data = getContractStatement.get(id);
- if (data === undefined) {
- return null;
- }
- return JSON.parse(data.data);
-}
-
-export function getContracts() {
- const data = getContractsStatement.all();
- return data.map(contractData => JSON.parse(contractData.data));
-}
-
-export function setContract(data) {
- if (getContract(data.id) === null) {
- return addContractStatement.run(JSON.stringify(data)).lastInsertRowid;
- } else {
- return updateContractStatement.run({
- data: JSON.stringify(data),
- id: data.id,
- }).changes;
- }
-}