Initial stage
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import mariadb from 'mariadb';
|
||||
|
||||
import { env } from '../config/env.js';
|
||||
|
||||
const pool = mariadb.createPool({
|
||||
host: env.db.host,
|
||||
port: env.db.port,
|
||||
database: env.db.database,
|
||||
user: env.db.user,
|
||||
password: env.db.password,
|
||||
connectionLimit: env.db.connectionLimit,
|
||||
bigIntAsNumber: true
|
||||
});
|
||||
|
||||
export async function query(sql, params = []) {
|
||||
let connection;
|
||||
|
||||
try {
|
||||
connection = await pool.getConnection();
|
||||
return await connection.query(sql, params);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function closePool() {
|
||||
await pool.end();
|
||||
}
|
||||
Reference in New Issue
Block a user