This commit is contained in:
parent
3b782c02fe
commit
94cc914926
BIN
mydb.sqlite
BIN
mydb.sqlite
Binary file not shown.
@ -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: <explanation>
|
||||
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);
|
||||
// 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user