From accb147b54bc99e5cd20059be5cb333031f15885 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sat, 18 Jul 2020 22:37:00 +0200
Subject: Added user registration

Co-authored-by: LarsVomMars <lars@kroenner.eu>
---
 src/db/DBController.ts | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

(limited to 'src/db/DBController.ts')

diff --git a/src/db/DBController.ts b/src/db/DBController.ts
index 416f695..1bb91ba 100644
--- a/src/db/DBController.ts
+++ b/src/db/DBController.ts
@@ -11,7 +11,6 @@ export default class DBController {
             const queries = sql.split(";");
             queries.pop();
             for (const query of queries) await this.execute(query);
-            // queries.forEach(async (query) => await this.execute(query));
             console.log("Tables created");
         } catch (e) {
             console.error("Could not create tables");
@@ -34,28 +33,30 @@ export default class DBController {
         }
     }
 
-    async query(query: string, params?: string[]) {
-        if (!this.client) throw Error("Database isn't initialized yet!");
+    async query(query: string, params?: (boolean | number | any)[]) {
+        if (!this.client) await this.connect();
 
         try {
-            return await this.client.query(query, params);
+            const res = await this.client!.query(query, params);
+            console.log(res);
+            return res;
         } catch (e) {
             throw e;
         }
     }
 
-    async execute(query: string, params?: string[]) {
-        if (!this.client) throw Error("Database isn't initialized yet!");
+    async execute(query: string, params?: (boolean | number | any)[]) {
+        if (!this.client) await this.connect();
 
         try {
-            return await this.client.execute(query, params);
+            return await this.client!.execute(query, params);
         } catch (e) {
             throw e;
         }
     }
 
-    async execute_multiple(queries: (string[] | string)[][]) {
-        if (!this.client) throw Error("Database isn't initialized yet!");
+    async execute_multiple(queries: ((boolean | number | any)[] | string)[][]) {
+        if (!this.client) await this.connect();
 
         try {
             await this.client!.transaction(async (conn) => {
-- 
cgit v1.2.3