Skip to content

Commit feb4fa6

Browse files
authored
Update README.md
1 parent 8498ee0 commit feb4fa6

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ fastify.register(require('fastify-oracle'), {
2424
})
2525

2626
fastify.get('/db_data', async function (req, reply) {
27+
let conn
2728
try {
28-
const conn = await this.oracle.getConnection()
29+
conn = await this.oracle.getConnection()
2930
const result = await conn.execute('select 1 as foo from dual')
3031
return result.rows
3132
} finally {
32-
conn.close()
33+
if (conn) {
34+
conn.close().catch((err) => {})
35+
}
3336
}
3437
})
3538

@@ -83,37 +86,46 @@ fastify
8386
})
8487

8588
fastify.get('/db_1_data', async function (req, reply) {
89+
let conn
8690
try {
87-
const conn = await this.oracle.ora1.getConnection()
91+
conn = await this.oracle.ora1.getConnection()
8892
const result = await conn.execute('select 1 as foo from dual')
8993
return result.rows
9094
} finally {
91-
conn.close()
92-
}
95+
if (conn) {
96+
conn.close().catch((err) => {})
97+
}
98+
}
9399
})
94100

95101
fastify.get('/db_2_data', async function (req, reply) {
102+
let conn
96103
try {
97-
const conn = await this.oracle.ora2.getConnection()
104+
conn = await this.oracle.ora2.getConnection()
98105
const result = await conn.execute('select 1 as foo from dual')
99106
return result.rows
100107
} finally {
101-
conn.close()
102-
}
108+
if (conn) {
109+
conn.close().catch((err) => {})
110+
}
111+
}
103112
})
104113
```
105114

106115
The `oracledb` instance is also available via `fastify.oracle.db` for accessing constants and other functionality:
107116

108117
```js
109118
fastify.get('/db_data', async function (req, reply) {
119+
let conn
110120
try {
111-
const conn = await this.oracle.ora1.getConnection()
121+
conn = await this.oracle.ora1.getConnection()
112122
const result = await conn.execute('select 1 as foo from dual', { }, { outFormat: this.oracle.db.OBJECT })
113123
return result.rows
114124
} finally {
115-
conn.close()
116-
}
125+
if (conn) {
126+
conn.close().catch((err) => {})
127+
}
128+
}
117129
})
118130
```
119131

0 commit comments

Comments
 (0)