aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-07-18 21:05:49 +0200
committerMarvin Borner2020-07-18 21:05:49 +0200
commitc96473af48f650ac568a9a9203f3d6bbe74ff080 (patch)
tree84c66793f25344de120d5bf26cf2f36bfaf0b80b
parent39254cbdaffe91c599ab268cef8999a16a0ef7f0 (diff)
Whoops forgot adding the significant files, fixing the test :)
-rw-r--r--src/db/DBController.ts13
-rw-r--r--src/db/user.ts4
-rw-r--r--src/handler/user.ts1
-rw-r--r--src/main.ts6
4 files changed, 14 insertions, 10 deletions
diff --git a/src/db/DBController.ts b/src/db/DBController.ts
index 4188bd1..416f695 100644
--- a/src/db/DBController.ts
+++ b/src/db/DBController.ts
@@ -10,7 +10,8 @@ export default class DBController {
const sql = await readFileStr("./src/db/tables.sql");
const queries = sql.split(";");
queries.pop();
- queries.forEach(async (query) => await this.execute(query));
+ 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");
@@ -18,7 +19,7 @@ export default class DBController {
}
}
- async connect() {
+ async connect(): Promise<Client> {
try {
this.client = await new Client().connect({
hostname: Deno.env.get("DBHost"),
@@ -26,6 +27,7 @@ export default class DBController {
db: Deno.env.get("DBName"),
password: Deno.env.get("DBPassword"),
});
+ return this.client;
} catch (e) {
console.error("Could not connect to database");
throw e;
@@ -52,15 +54,12 @@ export default class DBController {
}
}
- // deno-lint-ignore no-explicit-any
- async execute_multiple(queries: any[][]) {
+ async execute_multiple(queries: (string[] | string)[][]) {
if (!this.client) throw Error("Database isn't initialized yet!");
try {
await this.client!.transaction(async (conn) => {
- queries.forEach(async (query) => {
- await conn.execute(query[0], query[1]);
- });
+ for (const query of queries) await conn.execute(query[0] as string, query[1] as string[]); // ez
});
} catch (e) {
throw e;
diff --git a/src/db/user.ts b/src/db/user.ts
index 1e20564..c0cb127 100644
--- a/src/db/user.ts
+++ b/src/db/user.ts
@@ -1,7 +1,9 @@
import DBController from "./DBController.ts";
class User {
- createUser() {}
+ createUser() {
+
+ }
}
export default new User();
diff --git a/src/handler/user.ts b/src/handler/user.ts
index be4472b..28d6fbd 100644
--- a/src/handler/user.ts
+++ b/src/handler/user.ts
@@ -1,5 +1,4 @@
import type { HandlerFunc, Context } from "https://deno.land/x/abc@master/mod.ts";
-// import type { HandlerFunc, Context } from "../abc/mod.ts";
import db from "../db/user.ts";
export const index: HandlerFunc = async (c: Context) => c.params.name;
diff --git a/src/main.ts b/src/main.ts
index 667131c..1772e97 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -5,8 +5,12 @@ import { renderFile } from "https://deno.land/x/dejs/mod.ts";
import * as groups from "./groups/index.ts";
import DBController from "./db/DBController.ts";
+let dbc: DBController;
// Ugly solution
-(async () => await new DBController().init())();
+(async () => {
+ dbc = new DBController();
+ await dbc.init();
+})();
const port = parseInt(Deno.env.get("PORT") || "8080");
const app = new Application();