feat(database): Implement DatabaseManager for managing database structure and initialization
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 1m51s
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 1m51s
feat(routes): Add camera, image, measurement, project, and video routes with Swagger documentation feat(services): Create storageService and videoService for file management and video processing fix(errorHandler): Enhance error handling with standardized responses and database operation wrappers
This commit is contained in:
44
src/database/connection.js
Normal file
44
src/database/connection.js
Normal file
@@ -0,0 +1,44 @@
|
||||
// src/database/connection.js
|
||||
const { Client } = require('pg');
|
||||
const config = require('../config');
|
||||
|
||||
// Création du client PostgreSQL avec la configuration centralisée
|
||||
const client = new Client({
|
||||
host: config.database.host,
|
||||
port: config.database.port,
|
||||
user: config.database.user,
|
||||
password: config.database.password,
|
||||
database: config.database.database
|
||||
});
|
||||
|
||||
let isConnecting = false;
|
||||
|
||||
/**
|
||||
* Initialise la connexion à la base de données
|
||||
* Réessaie automatiquement si la connexion échoue
|
||||
*/
|
||||
function initDatabase() {
|
||||
if (isConnecting) {
|
||||
console.log('[DB] Tentative de connexion déjà en cours, ignorer...');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[DB] Initialisation de la connexion à PostgreSQL...');
|
||||
isConnecting = true;
|
||||
|
||||
client.connect(err => {
|
||||
isConnecting = false;
|
||||
|
||||
if (err) {
|
||||
console.error('[DB] Erreur de connexion à la base de données:', err);
|
||||
setTimeout(initDatabase, config.database.reconnectInterval);
|
||||
} else {
|
||||
console.log('[DB] Connecté à la base de données PostgreSQL.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialise la connexion lors de l'importation de ce module
|
||||
initDatabase();
|
||||
|
||||
module.exports = client;
|
||||
Reference in New Issue
Block a user