Skip to content

Commit 8498ee0

Browse files
authored
Update README.md
Updated examples
1 parent 6aca94f commit 8498ee0

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ fastify.register(require('fastify-oracle'), {
2424
})
2525

2626
fastify.get('/db_data', async function (req, reply) {
27-
const conn = await this.oracle.getConnection()
28-
const results = await conn.execute('select 1 as foo from dual')
29-
await conn.close()
30-
return results
27+
try {
28+
const conn = await this.oracle.getConnection()
29+
const result = await conn.execute('select 1 as foo from dual')
30+
return result.rows
31+
} finally {
32+
conn.close()
33+
}
3134
})
3235

3336
fastify.listen(3000, (err) => {
@@ -80,28 +83,37 @@ fastify
8083
})
8184

8285
fastify.get('/db_1_data', async function (req, reply) {
83-
const conn = await this.oracle.ora1.getConnection()
84-
const results = await conn.execute('select 1 as foo from dual')
85-
await conn.close()
86-
return results
86+
try {
87+
const conn = await this.oracle.ora1.getConnection()
88+
const result = await conn.execute('select 1 as foo from dual')
89+
return result.rows
90+
} finally {
91+
conn.close()
92+
}
8793
})
8894

8995
fastify.get('/db_2_data', async function (req, reply) {
90-
const conn = await this.oracle.ora2.getConnection()
91-
const results = await conn.execute('select 1 as foo from dual')
92-
await conn.close()
93-
return results
96+
try {
97+
const conn = await this.oracle.ora2.getConnection()
98+
const result = await conn.execute('select 1 as foo from dual')
99+
return result.rows
100+
} finally {
101+
conn.close()
102+
}
94103
})
95104
```
96105

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

99108
```js
100109
fastify.get('/db_data', async function (req, reply) {
101-
const conn = await this.oracle.getConnection()
102-
const results = await conn.execute('select 1 as foo from dual', { }, { outFormat: this.oracle.db.OBJECT })
103-
await conn.close()
104-
return results
110+
try {
111+
const conn = await this.oracle.ora1.getConnection()
112+
const result = await conn.execute('select 1 as foo from dual', { }, { outFormat: this.oracle.db.OBJECT })
113+
return result.rows
114+
} finally {
115+
conn.close()
116+
}
105117
})
106118
```
107119

@@ -115,4 +127,4 @@ If needed `pool` instance can be accessed via `fastify.oracle[.dbname].pool`
115127

116128
Thanks to
117129
- [James Sumners](https://github.com/jsumners), who is the original author of this plugin, for his work and transferring his repository to me.
118-
- [Vincit](https://github.com/Vincit/travis-oracledb-xe) for his Travis Oracle work.
130+
- [Vincit](https://github.com/Vincit/travis-oracledb-xe) for his Travis Oracle work.

0 commit comments

Comments
 (0)