fastify-oracle
This module provides access to an Oracle database connection pool via the
oracledb module. It decorates the Fastify
instance with an oracle
property that is a connection pool instance.
When the Fastify server is shutdown, this plugin invokes the .close()
method
on the connection pool.
Examples
The plugin provides the basic functionality for creating a connection and executing statements such as
const fastify = fastify fastify fastify
The transact
feature can be used for convenience to avoid the repetetive task of setting up a connection, committing, releasing etc. as follows:
const fastify = fastify fastify /* or with a transact callback fastify.oracle.transact(conn => { return conn.execute('SELECT * FROM DUAL') }, function onResult (err, result) { reply.send(err || result) }}) */ /* or with a commit callback fastify.oracle.transact((conn, commit) => { conn.execute('SELECT * FROM DUAL', (err, res) => { commit(err, res) });}) */
Options
fastify-oracle
requires an options object with at least one of the following
properties:
pool
: anoracledb
pool configuration objectpoolAlias
: the name of a pool alias that has already been configured. This takes precedence over thepool
option.client
: an instance of anoracledb
connection pool. This takes precedence over thepool
andpoolAlias
options.name
: (optional) can be used in order to connect to multiple oracledb instances. The first registered instance can be accessed viafastify.oracle
orfastify.oracle.<dbname>
. Note that once you register a named instance, you will not be able to register an unnamed instance.outFormat
: (optional) sets theoutFormat
of oracledb. Should be'ARRAY'
or'OBJECT'
. Default:'ARRAY'
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. Valid values are['DATE', 'NUMBER', 'BUFFER', 'CLOB']
. Default[]
.
const fastify = fastify fastify fastify
The oracledb
instance is also available via fastify.oracle.db
for accessing constants and other functionality:
fastify
If needed pool
instance can be accessed via fastify.oracle[.dbname].pool
License
Acknowledgements
Thanks to
- James Sumners, who is the original author of this plugin, for his work and transferring his repository to me.
- Vincit for his Travis Oracle work.