File tree Expand file tree Collapse file tree 2 files changed +22
-20
lines changed Expand file tree Collapse file tree 2 files changed +22
-20
lines changed Original file line number Diff line number Diff line change 4
4
** All rights reserved
5
5
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
*/
7
+
8
+ // app/server/utils/db/config.cjs
7
9
const oracledb = require ( 'oracledb' ) ;
8
10
const dbConfig = require ( './config.cjs' ) ;
9
11
@@ -15,24 +17,24 @@ class DBConnector {
15
17
this . pool = null ;
16
18
}
17
19
18
- async init ( ) {
19
- try {
20
- this . pool = await oracledb . createPool ( {
21
- ...dbConfig ,
22
- poolMax : 10 ,
23
- poolMin : 10
24
- } ) ;
25
- console . log ( 'Connection pool created successfully.' ) ;
26
- } catch ( error ) {
27
- console . error ( 'Error creating connection pool:' , error ) ;
28
- throw error ;
20
+ async createPool ( ) {
21
+ if ( ! this . pool ) {
22
+ try {
23
+ this . pool = await oracledb . createPool ( {
24
+ ...dbConfig ,
25
+ poolMax : 10 ,
26
+ poolMin : 10
27
+ } ) ;
28
+ console . log ( 'Connection pool created successfully.' ) ;
29
+ } catch ( error ) {
30
+ console . error ( 'Error creating connection pool:' , error ) ;
31
+ throw error ;
32
+ }
29
33
}
30
34
}
31
35
32
36
async getConnection ( options = { } ) {
33
- if ( ! this . pool ) {
34
- throw new Error ( 'Connection pool not initialized.' ) ;
35
- }
37
+ await this . createPool ( ) ;
36
38
try {
37
39
const connection = await this . pool . getConnection ( {
38
40
...dbConfig ,
@@ -46,4 +48,4 @@ class DBConnector {
46
48
}
47
49
}
48
50
49
- module . exports = new DBConnector ( ) ;
51
+ module . exports = new DBConnector ( ) ;
Original file line number Diff line number Diff line change 4
4
** All rights reserved
5
5
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
*/
7
- const db = require ( '../db/index.cjs' ) ;
7
+
8
+ const db = require ( '../db/index.cjs' ) ;
8
9
9
10
exports . getStatus = async function ( ) {
10
- await db . init ( ) ;
11
11
const connection = await db . getConnection ( ) ;
12
- const result = await connection . execute ( 'select 1 from dual' ) ;
12
+ const result = await connection . execute ( 'select 1 from dual' ) ;
13
13
await connection . close ( ) ;
14
14
15
15
return {
16
16
status : 'ok' ,
17
- }
18
- } ;
17
+ } ;
18
+ } ;
You can’t perform that action at this time.
0 commit comments