🚀 Backend komplett implementiert
Features: - Auth mit JWT + Argon2 (Login, Register, Refresh) - Rollen-System (Chef/Disponent/Mitarbeiter) - User Management mit Berechtigungen - Aufträge mit Zuweisungen - Verfügbarkeitsplanung - Stundenzettel mit Foto-Upload Support - Modulares System mit Config - Entwickler-Panel Endpoints Tech: - Deno + Oak - PostgreSQL - CORS enabled
This commit is contained in:
54
src/db/postgres.ts
Normal file
54
src/db/postgres.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Pool } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
|
||||
|
||||
const DATABASE_URL = Deno.env.get("DATABASE_URL") ||
|
||||
"postgres://secu:SeCu2026!SecureDB@localhost:5434/secu";
|
||||
|
||||
let pool: Pool;
|
||||
|
||||
export async function initDB(): Promise<void> {
|
||||
pool = new Pool(DATABASE_URL, 10);
|
||||
|
||||
// Test connection
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
const result = await client.queryObject`SELECT NOW()`;
|
||||
console.log("✅ Database connected:", result.rows[0]);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
export function getPool(): Pool {
|
||||
return pool;
|
||||
}
|
||||
|
||||
export async function query<T>(sql: string, params?: unknown[]): Promise<T[]> {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
const result = await client.queryObject<T>({
|
||||
text: sql,
|
||||
args: params || [],
|
||||
});
|
||||
return result.rows;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
export async function queryOne<T>(sql: string, params?: unknown[]): Promise<T | null> {
|
||||
const rows = await query<T>(sql, params);
|
||||
return rows[0] || null;
|
||||
}
|
||||
|
||||
export async function execute(sql: string, params?: unknown[]): Promise<number> {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
const result = await client.queryObject({
|
||||
text: sql,
|
||||
args: params || [],
|
||||
});
|
||||
return result.rowCount || 0;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user