@@ -24,10 +24,13 @@ fastify.register(require('fastify-oracle'), {
24
24
})
25
25
26
26
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
+ }
31
34
})
32
35
33
36
fastify .listen (3000 , (err ) => {
@@ -80,28 +83,37 @@ fastify
80
83
})
81
84
82
85
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
+ }
87
93
})
88
94
89
95
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
+ }
94
103
})
95
104
```
96
105
97
106
The ` oracledb ` instance is also available via ` fastify.oracle.db ` for accessing constants and other functionality:
98
107
99
108
``` js
100
109
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
+ }
105
117
})
106
118
```
107
119
@@ -115,4 +127,4 @@ If needed `pool` instance can be accessed via `fastify.oracle[.dbname].pool`
115
127
116
128
Thanks to
117
129
- [ 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