summaryrefslogtreecommitdiff
path: root/nodejs/database
diff options
context:
space:
mode:
authorJulien Dessaux2023-09-08 22:34:22 +0200
committerJulien Dessaux2023-09-08 22:34:22 +0200
commit2ae1d4e8fd7b8d295b12d73d55f25e709bbce355 (patch)
tree1e437389fb5250bb6c84585583cb1e9129faa052 /nodejs/database
parent[javascript] Fixed database functions result which were not parsed (diff)
downloadspacetraders-2ae1d4e8fd7b8d295b12d73d55f25e709bbce355.tar.gz
spacetraders-2ae1d4e8fd7b8d295b12d73d55f25e709bbce355.tar.bz2
spacetraders-2ae1d4e8fd7b8d295b12d73d55f25e709bbce355.zip
[javascript] add database function to fetch all contracts
Diffstat (limited to 'nodejs/database')
-rw-r--r--nodejs/database/contracts.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/nodejs/database/contracts.js b/nodejs/database/contracts.js
index ac583de..d7f9aab 100644
--- a/nodejs/database/contracts.js
+++ b/nodejs/database/contracts.js
@@ -2,6 +2,7 @@ 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) {
@@ -12,6 +13,11 @@ export function getContract(id) {
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;