From 94cc914926154e2cfa6e9f990ce9962cf95c33eb Mon Sep 17 00:00:00 2001 From: moriese Date: Sat, 25 Jan 2025 14:47:23 +0100 Subject: [PATCH] i try to fix lmao --- mydb.sqlite | Bin 0 -> 16384 bytes src/db/index.ts | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mydb.sqlite b/mydb.sqlite index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5bf3c9ea8694129c7da67423708a0ba3786e2787 100644 GIT binary patch literal 16384 zcmeI%O-sWt7zgmw4VA%OZo57(1jmLih)2PyQHotRXAABW>KdVLYjMp$uj1YB#zI9R<%|$-gc&AP7*mz#OmwDkFl0wXtzMK z6b58DF2CYk>U6D^+3nFa?~&=bZOhU9TikJ*^XPPba`~N0PFrWswij(dnDpauAeKhV zg2;2M8;>tyALB3*i5g3PkWIg69Quh8X@m@fzH85xw`f;!JP;!pgneIyaU@h6_%B)5 zd|`CKFHO&O>0rA0`tinQ)v6gRi~{*QbM+@mPowK%2}c|*RdV{MZKubrm_91$0|^2U zfB*y_009U<00Izz00bZafprxqq#MKie_cN>_5}e5KmY;|fB*y_009U<00I!03gG`g b4gv%q009U<00Izz00bZa0SG`~{RO@O<0_E@ literal 0 HcmV?d00001 diff --git a/src/db/index.ts b/src/db/index.ts index a504a3a..cd5f599 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -2,17 +2,35 @@ import fs from 'node:fs'; import path from 'node:path'; import { drizzle } from "drizzle-orm/bun-sqlite"; import { Database } from 'bun:sqlite'; +import { usersTable } from './schema'; // Importiere die Tabelle hier // biome-ignore lint/style/noNonNullAssertion: const dbPath = process.env.DB_FILE_NAME!; const dbDir = path.dirname(dbPath); -// Create directory if it doesn't exist +// Erstelle das Verzeichnis, wenn es noch nicht existiert if (!fs.existsSync(dbDir)) { fs.mkdirSync(dbDir, { recursive: true }); } -// Ensure database file can be created +// Wenn die Datenbankdatei nicht existiert, dann erstelle sie +if (!fs.existsSync(dbPath)) { + fs.writeFileSync(dbPath, ''); // Leere Datei erstellen +} + +// Datenbankverbindung herstellen const client = new Database(dbPath); -export const db = drizzle(client); \ No newline at end of file +// Stelle sicher, dass die Tabelle existiert +client.run(` + CREATE TABLE IF NOT EXISTS users_table ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + discord_id INTEGER NOT NULL UNIQUE, + join_streak INTEGER, + last_joined_at INTEGER, + took_medication_today INTEGER NOT NULL DEFAULT 0 + ); +`); + +export const db = drizzle(client);