für Docker angepasst
This commit is contained in:
29
lib/db.ts
Normal file
29
lib/db.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import mysql from 'mysql2/promise';
|
||||
import type { QueryResult } from 'mysql2/promise';
|
||||
|
||||
// Database configuration
|
||||
const dbConfig = {
|
||||
host: process.env.DB_HOST || 'mydbase_mysql',
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASS || 'SFluorit',
|
||||
database: process.env.DB_NAME || 'RXF',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
};
|
||||
|
||||
// Create a connection pool
|
||||
let pool: mysql.Pool | null = null;
|
||||
|
||||
export function getPool() {
|
||||
if (!pool) {
|
||||
pool = mysql.createPool(dbConfig);
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
export async function query(sql: string, params?: (string | number | null)[]): Promise<QueryResult> {
|
||||
const pool = getPool();
|
||||
const [rows] = await pool.execute(sql, params || []);
|
||||
return rows as QueryResult;
|
||||
}
|
||||
Reference in New Issue
Block a user