aboutsummaryrefslogtreecommitdiff
path: root/src/db/DBController.ts
diff options
context:
space:
mode:
authorMarvin Borner2020-07-18 18:34:32 +0200
committerMarvin Borner2020-07-18 18:34:32 +0200
commit26f84c953f9fbb9c5afb4f8a063759d272256f36 (patch)
tree653e4beb8353ed05dc800d67061502ea5abdcae4 /src/db/DBController.ts
parentecbb3c7420ebb63d9a870760df602b27cef82939 (diff)
More database tests!
Diffstat (limited to 'src/db/DBController.ts')
-rw-r--r--src/db/DBController.ts36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/db/DBController.ts b/src/db/DBController.ts
index c01d7b4..274e446 100644
--- a/src/db/DBController.ts
+++ b/src/db/DBController.ts
@@ -15,8 +15,6 @@ export default class DBController {
} catch (e) {
console.error("Could not create tables");
throw e;
- } finally {
- this.client.close();
}
}
@@ -34,21 +32,33 @@ export default class DBController {
}
}
+ async query(query: string, params?: string[]) {
+ if (!this.client) throw Error("Database isn't initialized yet!");
+
+ try {
+ return await this.client.query(query, params);
+ } catch (e) {
+ throw e;
+ }
+ }
+
async execute(query: string, params?: string[]) {
- if (this.client) {
- try {
- return await this.client.execute(query, params);
- } catch (e) {
- throw e;
- }
- } else throw Error("Database isn't initialized yet!");
+ if (!this.client) throw Error("Database isn't initialized yet!");
+
+ try {
+ await this.client.execute(query, params);
+ } catch (e) {
+ throw e;
+ }
}
- async execute_multiple(queries: string[]) {
+ async execute_multiple(queries: any[][]) {
+ if (!this.client) throw Error("Database isn't initialized yet!");
+
try {
- return await this.client!.transaction(async (conn) => {
+ await this.client!.transaction(async (conn) => {
queries.forEach(async (query) => {
- await conn.execute(query);
+ await conn.execute(query[0], query[1]);
});
});
} catch (e) {
@@ -57,6 +67,8 @@ export default class DBController {
}
async close() {
+ if (!this.client) throw Error("Database isn't initialized yet!");
+
await this.client!.close();
}
}