Skip to content

Commit 9549caa

Browse files
committed
Update readme
1 parent 45fbe11 commit 9549caa

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,58 @@ takes precedence over the `pool` option.
5454
+ `client`: an instance of an `oracledb` connection pool. This takes precedence
5555
over the `pool` and `poolAlias` options.
5656

57+
A `name` option can be used in order to connect to multiple oracledb instances.
58+
The first registered instance can be accessed via `fastify.oracle` or `fastify.oracle.<dbname>`. Note that once you register a *named* instance, you will *not* be able to register an unnamed instance.
59+
60+
```js
61+
const fastify = require('fastify')()
62+
63+
fastify
64+
.register(require('fastify-oracle'), {
65+
pool: {
66+
user: 'foo',
67+
password: 'bar',
68+
connectString: 'oracle.example.com:1521/ora1'
69+
},
70+
name: 'ora1'
71+
})
72+
.register(require('fastify-oracle'), {
73+
pool: {
74+
user: 'foo',
75+
password: 'bar',
76+
connectString: 'oracle.example.com:1521/ora2'
77+
},
78+
name: 'ora2'
79+
})
80+
81+
fastify.get('/db_1_data', async function (req, reply) {
82+
const conn = await this.oracle.ora1.getConnection()
83+
const results = await conn.execute('select 1 as foo from dual')
84+
await conn.close()
85+
return results
86+
})
87+
88+
fastify.get('/db_2_data', async function (req, reply) {
89+
const conn = await this.oracle.ora2.getConnection()
90+
const results = await conn.execute('select 1 as foo from dual')
91+
await conn.close()
92+
return results
93+
})
94+
```
95+
96+
The `oracledb` instance is also available via `fastify.oracle.db` for accessing constants and other functionality:
97+
98+
```js
99+
fastify.get('/db_data', async function (req, reply) {
100+
const conn = await this.oracle.getConnection()
101+
const results = await conn.execute('select 1 as foo from dual', { }, { outFormat: this.oracle.db.OBJECT })
102+
await conn.close()
103+
return results
104+
})
105+
```
106+
107+
If needed `pool` instance can be accessed via `fastify.oracle[.dbname].pool`
108+
57109
## License
58110

59111
[MIT License](http://jsumners.mit-license.org/)

0 commit comments

Comments
 (0)