29 lines
732 B
JavaScript
Executable file
29 lines
732 B
JavaScript
Executable file
import mariadb from 'mariadb';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
// Create a pool without database selection first
|
|
const initialPool = mariadb.createPool({
|
|
host: '172.10.1.4', // Remote database host
|
|
user: 'handball', // Remote database user
|
|
password: 'Gabi2104@', // Remote database password
|
|
database: 'handball', // Database name
|
|
connectionLimit: 5
|
|
});
|
|
|
|
export const pool = initialPool;
|
|
|
|
export async function query(sql, params) {
|
|
let conn;
|
|
try {
|
|
conn = await pool.getConnection();
|
|
const result = await conn.query(sql, params);
|
|
return result;
|
|
} catch (error) {
|
|
console.error('Database query error:', error);
|
|
throw error;
|
|
} finally {
|
|
if (conn) conn.release();
|
|
}
|
|
}
|