@@ -24,12 +24,15 @@ fastify.register(require('fastify-oracle'), {
24
24
})
25
25
26
26
fastify .get (' /db_data' , async function (req , reply ) {
27
+ let conn
27
28
try {
28
- const conn = await this .oracle .getConnection ()
29
+ conn = await this .oracle .getConnection ()
29
30
const result = await conn .execute (' select 1 as foo from dual' )
30
31
return result .rows
31
32
} finally {
32
- conn .close ()
33
+ if (conn) {
34
+ conn .close ().catch ((err ) => {})
35
+ }
33
36
}
34
37
})
35
38
@@ -83,37 +86,46 @@ fastify
83
86
})
84
87
85
88
fastify .get (' /db_1_data' , async function (req , reply ) {
89
+ let conn
86
90
try {
87
- const conn = await this .oracle .ora1 .getConnection ()
91
+ conn = await this .oracle .ora1 .getConnection ()
88
92
const result = await conn .execute (' select 1 as foo from dual' )
89
93
return result .rows
90
94
} finally {
91
- conn .close ()
92
- }
95
+ if (conn) {
96
+ conn .close ().catch ((err ) => {})
97
+ }
98
+ }
93
99
})
94
100
95
101
fastify .get (' /db_2_data' , async function (req , reply ) {
102
+ let conn
96
103
try {
97
- const conn = await this .oracle .ora2 .getConnection ()
104
+ conn = await this .oracle .ora2 .getConnection ()
98
105
const result = await conn .execute (' select 1 as foo from dual' )
99
106
return result .rows
100
107
} finally {
101
- conn .close ()
102
- }
108
+ if (conn) {
109
+ conn .close ().catch ((err ) => {})
110
+ }
111
+ }
103
112
})
104
113
```
105
114
106
115
The ` oracledb ` instance is also available via ` fastify.oracle.db ` for accessing constants and other functionality:
107
116
108
117
``` js
109
118
fastify .get (' /db_data' , async function (req , reply ) {
119
+ let conn
110
120
try {
111
- const conn = await this .oracle .ora1 .getConnection ()
121
+ conn = await this .oracle .ora1 .getConnection ()
112
122
const result = await conn .execute (' select 1 as foo from dual' , { }, { outFormat: this .oracle .db .OBJECT })
113
123
return result .rows
114
124
} finally {
115
- conn .close ()
116
- }
125
+ if (conn) {
126
+ conn .close ().catch ((err ) => {})
127
+ }
128
+ }
117
129
})
118
130
```
119
131
0 commit comments