Skip to content

Commit b05e22e

Browse files
authored
Merge pull request #20 from cemremengu/prep-4.x
Update for 4.x
2 parents ed01350 + bab2eb2 commit b05e22e

File tree

6 files changed

+48
-28
lines changed

6 files changed

+48
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ sudo: required
33
dist: xenial
44

55
node_js:
6+
- "11"
67
- "10"
78
- "8"
89
- "6"
910

1011
script:
11-
- npm run lint
1212
- npm run test
1313

1414
env:

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,16 @@ fastify.oracle.transact((conn, commit) => {
103103
`fastify-oracle` requires an options object with at least one of the following
104104
properties:
105105

106-
+ `pool`: an `oracledb` [pool configuration object](https://github.com/oracle/node-oracledb/blob/33331413/doc/api.md#createpool)
107-
+ `poolAlias`: the name of a pool alias that has already been configured. This
106+
- `pool`: an `oracledb` [pool configuration object](https://github.com/oracle/node-oracledb/blob/33331413/doc/api.md#createpool)
107+
- `poolAlias`: the name of a pool alias that has already been configured. This
108108
takes precedence over the `pool` option.
109-
+ `client`: an instance of an `oracledb` connection pool. This takes precedence
109+
- `client`: an instance of an `oracledb` connection pool. This takes precedence
110110
over the `pool` and `poolAlias` options.
111-
+ `name`: can be used in order to connect to multiple oracledb instances. 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.
112-
+ `objectOutput`: sets the `outFormat` of oracledb to `OBJECT` (default: `false` i.e: `ARRAY`)
111+
- `name`: (optional) can be used in order to connect to multiple oracledb instances. 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.
112+
- `outFormat`: (optional) sets the `outFormat` of oracledb. Should be `'ARRAY'` or `'OBJECT'`. Default: `'ARRAY'`
113+
- `fetchAsString`: (optional) the column data of specified types are returned as a string instead of the default representation. Should be an array of valid data types.
114+
Valid values are `['DATE', 'NUMBER', 'BUFFER', 'CLOB']`. Default `[]`.
115+
113116

114117
```js
115118
const fastify = require('fastify')()
@@ -140,7 +143,7 @@ fastify.get('/db_1_data', async function (req, reply) {
140143
return result.rows
141144
} finally {
142145
if (conn) {
143-
conn.close().catch((err) => {})
146+
conn.close().catch((err) => {})
144147
}
145148
}
146149
})
@@ -153,7 +156,7 @@ fastify.get('/db_2_data', async function (req, reply) {
153156
return result.rows
154157
} finally {
155158
if (conn) {
156-
conn.close().catch((err) => {})
159+
conn.close().catch((err) => {})
157160
}
158161
}
159162
})
@@ -170,7 +173,7 @@ fastify.get('/db_data', async function (req, reply) {
170173
return result.rows
171174
} finally {
172175
if (conn) {
173-
conn.close().catch((err) => {})
176+
conn.close().catch((err) => {})
174177
}
175178
}
176179
})

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"description": "A plugin for Fastify to provide Oracle DB connections",
55
"main": "plugin.js",
66
"scripts": {
7-
"test": "standard && tap --cov test/*.test.js",
8-
"lint": "standard | snazzy"
7+
"pretest": "npm run lint",
8+
"test": " tap --cov test/*.test.js",
9+
"lint": "standard --fix | snazzy"
910
},
1011
"precommit": [
11-
"lint",
1212
"test"
1313
],
1414
"repository": {
@@ -26,14 +26,14 @@
2626
},
2727
"homepage": "https://github.com/cemremengu/fastify-oracle#readme",
2828
"devDependencies": {
29-
"fastify": "^1.11.1",
29+
"fastify": "^1.13.3",
3030
"pre-commit": "^1.2.2",
3131
"snazzy": "^8.0.0",
3232
"standard": "^12.0.1",
33-
"tap": "^12.0.1"
33+
"tap": "^12.1.1"
3434
},
3535
"dependencies": {
36-
"fastify-plugin": "^1.2.0",
37-
"oracledb": "^2.1.2"
36+
"fastify-plugin": "^1.4.0",
37+
"oracledb": "^3.0.1"
3838
}
3939
}

plugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ function fastifyOracleDB (fastify, options, next) {
9595
return next(Error('fastify-oracle: must supply options.pool oracledb pool options'))
9696
}
9797

98-
if (options.objectOutput) {
99-
oracledb.outFormat = oracledb.OBJECT
98+
if (options.outFormat) {
99+
oracledb.outFormat = oracledb[options.outFormat.toUpperCase()]
100+
}
101+
102+
if (options.fetchAsString) {
103+
oracledb.fetchAsString = options.fetchAsString.map(t => oracledb[t.toUpperCase()])
100104
}
101105

102106
oracledb.createPool(options.pool, (err, pool) => {

test/opts.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test('sets OBJECT as default outFormat', (t) => {
9292
oracledb.outFormat = oracledb.ARRAY
9393

9494
const fastify = Fastify()
95-
fastify.register(plugin, { pool: {}, objectOutput: true })
95+
fastify.register(plugin, { pool: {}, outFormat: 'OBJECT' })
9696

9797
fastify.ready(err => {
9898
t.error(err)
@@ -101,3 +101,16 @@ test('sets OBJECT as default outFormat', (t) => {
101101
oracledb.outFormat = oracledb.ARRAY
102102
})
103103
})
104+
105+
test('sets fetchAsString values', (t) => {
106+
t.plan(3)
107+
108+
const fastify = Fastify()
109+
fastify.register(plugin, { pool: {}, fetchAsString: ['NUMBER'] })
110+
111+
fastify.ready(err => {
112+
t.error(err)
113+
t.ok(fastify.oracle.pool)
114+
t.deepEquals(fastify.oracle.db.fetchAsString, [fastify.oracle.db.NUMBER])
115+
})
116+
})

test/plugin.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test('transact with promise', (t) => {
120120
t.plan(6)
121121

122122
const fastify = Fastify()
123-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
123+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
124124

125125
fastify.ready(err => {
126126
t.error(err)
@@ -144,7 +144,7 @@ test('transact with callback', (t) => {
144144
t.plan(6)
145145

146146
const fastify = Fastify()
147-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
147+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
148148

149149
fastify.ready(err => {
150150
t.error(err)
@@ -168,7 +168,7 @@ test('transact with commit callback', (t) => {
168168
t.plan(6)
169169

170170
const fastify = Fastify()
171-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
171+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
172172

173173
fastify.ready(err => {
174174
t.error(err)
@@ -193,7 +193,7 @@ test('transact with promise (error)', (t) => {
193193
t.plan(5)
194194

195195
const fastify = Fastify()
196-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
196+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
197197

198198
fastify.ready(err => {
199199
t.error(err)
@@ -216,7 +216,7 @@ test('transact with callback (error)', (t) => {
216216
t.plan(6)
217217

218218
const fastify = Fastify()
219-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
219+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
220220

221221
fastify.ready(err => {
222222
t.error(err)
@@ -240,7 +240,7 @@ test('transact with commit callback (error)', (t) => {
240240
t.plan(6)
241241

242242
const fastify = Fastify()
243-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
243+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
244244

245245
fastify.ready(err => {
246246
t.error(err)
@@ -265,7 +265,7 @@ test('transact with callback + invalid connection pool', (t) => {
265265
t.plan(6)
266266

267267
const fastify = Fastify()
268-
fastify.register(plugin, { pool: {}, objectOutput: true })
268+
fastify.register(plugin, { pool: {}, outFormat: 'object' })
269269

270270
fastify.ready(err => {
271271
t.error(err)
@@ -289,7 +289,7 @@ test('transact with promise + invalid connection pool', (t) => {
289289
t.plan(5)
290290

291291
const fastify = Fastify()
292-
fastify.register(plugin, { pool: {}, objectOutput: true })
292+
fastify.register(plugin, { pool: {}, outFormat: 'OBJECT' })
293293

294294
fastify.ready(err => {
295295
t.error(err)
@@ -312,7 +312,7 @@ test('transact commit should error if connection drops', (t) => {
312312
t.plan(6)
313313

314314
const fastify = Fastify()
315-
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
315+
fastify.register(plugin, { pool: poolOptions, outFormat: 'OBJECT' })
316316

317317
fastify.ready(err => {
318318
t.error(err)

0 commit comments

Comments
 (0)