Skip to content

Commit

Permalink
Add option to set global oracledb options
Browse files Browse the repository at this point in the history
  • Loading branch information
cemremengu committed Oct 9, 2018
1 parent 27d0d29 commit 6d0f3da
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function decorateFastifyInstance (pool, fastify, options, next) {
}

function fastifyOracleDB (fastify, options, next) {
if (options.oracledb) {
Object.assign(oracledb, options.oracledb)
}

if (options.client) {
if (oracledb.Pool.prototype.isPrototypeOf(options.client) === false) {
return next(Error('supplied client must be an instance of oracledb.pool'))
Expand Down
43 changes: 43 additions & 0 deletions test/options.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const test = require('tap').test
const plugin = require('../plugin')
const oracledb = require('oracledb')

test('should set oracledb options globally', (t) => {
t.plan(6)

const fastify = {
decorate (name, obj) {
t.is(name, 'oracle')
this[name] = obj
},

addHook (name, fn) {
t.is(name, 'onClose')
t.match(fn, /fastify\.oracle\.pool\.close/)
}
}

const opts = {
user: 'travis',
password: 'travis',
connectString: 'localhost/xe'
}
// default outFormat is array
plugin(fastify, { pool: opts, oracledb: { outFormat: oracledb.OBJECT } }, (err) => {
if (err) t.threw(err)
t.ok(fastify.oracle)
fastify.oracle.getConnection()
.then((conn) => {
conn.execute('SELECT 1 AS FOO FROM DUAL')
.then((result) => {
t.is(result.rows.length, 1)
t.is(result.rows[0].FOO, 1)
})
.then(() => conn.close())
.catch(t.threw)
})
.catch(t.threw)
})
})

0 comments on commit 6d0f3da

Please sign in to comment.