@@ -11,8 +11,7 @@ export class ConnectionPool {
11
11
}
12
12
async connect ( ) : Promise < boolean > {
13
13
try {
14
- const client = await this . _pool . connect ( ) ;
15
- client . release ( ) ;
14
+ await this . _pool . connect ( ) ;
16
15
logger . info ( 'Database connection successful' ) ;
17
16
return true ;
18
17
} catch ( error : any ) {
@@ -23,7 +22,6 @@ export class ConnectionPool {
23
22
await this . reinitializePool ( ) ;
24
23
try {
25
24
const client = await this . _pool . connect ( ) ;
26
- client . release ( ) ;
27
25
logger . info ( 'Database connection successful after reinitialization' ) ;
28
26
return true ;
29
27
} catch ( reconnectError : any ) {
@@ -45,12 +43,8 @@ export class ConnectionPool {
45
43
port,
46
44
database : 'postgres' ,
47
45
} ) ;
48
- try {
49
- await client . query ( `CREATE DATABASE "${ databaseName } "` ) ;
50
- console . log ( `Database "${ databaseName } " created successfully.` ) ;
51
- } finally {
52
- await client . end ( ) ;
53
- }
46
+ await client . query ( `CREATE DATABASE "${ databaseName } "` ) ;
47
+ console . log ( `Database "${ databaseName } " created successfully.` ) ;
54
48
}
55
49
private getConnectionString ( ) : string {
56
50
const { user, host, databaseName, password, port, url } = Config . database ;
@@ -73,7 +67,7 @@ export class ConnectionPool {
73
67
keepAlive : true ,
74
68
} ) ;
75
69
}
76
- private async reinitializePool ( ) {
70
+ async reinitializePool ( ) {
77
71
await this . _pool . end ( ) ; // Close old connections
78
72
const newConnectionString = this . getConnectionString ( ) ;
79
73
this . _pool = this . initializePool ( newConnectionString ) ;
0 commit comments