@@ -9,6 +9,19 @@ import { Logger, OracleDBCredentials, OracleDBOptions } from './types';
99
1010oracledb . outFormat = oracledb . OUT_FORMAT_OBJECT ;
1111
12+ /**
13+ * The default options for the Oracle Wrapper
14+ */
15+
16+ const defaultOptions : OracleDBOptions = {
17+ logger : console ,
18+ poolMin : 0 ,
19+ poolMax : 2 ,
20+ poolIncrement : 1 ,
21+ poolCloseTimeout : 60 ,
22+ prefetchRowCount : 1000 ,
23+ } ;
24+
1225/**
1326 * Interface to the Oracle database
1427 */
@@ -36,26 +49,42 @@ export default class OracleWrapper {
3649 */
3750 private poolCredentials : PoolAttributes ;
3851
52+ /**
53+ * The amount of time to wait for the connection pool to close
54+ */
55+ private poolCloseTimeout : number ;
56+
57+ /**
58+ * the number of rows that should be fetched at one time
59+ */
60+ private prefetchRowCount : number ;
61+
3962 /**
4063 * Create a new oracle interface
4164 */
4265 public constructor (
4366 credentials : OracleDBCredentials ,
44- options : OracleDBOptions = { }
67+ userOptions : OracleDBOptions = { }
4568 ) {
4669 const {
4770 host, port, sid, user, password,
4871 } = credentials ;
72+ const options = {
73+ ...defaultOptions ,
74+ ...userOptions ,
75+ } ;
4976 this . alias = options . alias || sid ;
50- this . logger = options . logger || console ;
77+ this . logger = options . logger ;
78+ this . poolCloseTimeout = options . poolCloseTimeout ;
79+ this . prefetchRowCount = options . prefetchRowCount ;
5180 this . poolCredentials = {
5281 user,
5382 password,
5483 poolAlias : this . alias ,
5584 connectionString : `${ host } :${ port } /${ sid } ` ,
56- poolMin : 0 ,
57- poolMax : 2 ,
58- poolIncrement : 1 ,
85+ poolMin : options . poolMin ,
86+ poolMax : options . poolMax ,
87+ poolIncrement : options . poolIncrement ,
5988 } ;
6089 }
6190
@@ -87,7 +116,7 @@ export default class OracleWrapper {
87116 public async releasePool ( ) : Promise < void > {
88117 if ( this . connectionPool ) {
89118 try {
90- await this . connectionPool . close ( 60 ) ;
119+ await this . connectionPool . close ( this . poolCloseTimeout ) ;
91120 this . connectionPool = null ;
92121 this . logger . info ( 'Connection pool released' ) ;
93122 } catch ( err ) {
@@ -106,10 +135,9 @@ export default class OracleWrapper {
106135 query : string ,
107136 variables : Record < string , unknown > = { }
108137 ) : Promise < T [ ] > {
109- const ROW_COUNT = 1000 ;
110138 const options = {
111139 resultSet : true ,
112- prefetchRows : ROW_COUNT ,
140+ prefetchRows : this . prefetchRowCount ,
113141 } ;
114142 const conn = await this . getConnection ( ) ;
115143 // Execute Query
@@ -127,7 +155,7 @@ export default class OracleWrapper {
127155 // https://jsao.io/2015/07/an-overview-of-result-sets-in-the-nodejs-driver/
128156 try {
129157 const fetchAndConcat = async ( prevRows : T [ ] ) : Promise < T [ ] > => {
130- const rows = await result . resultSet . getRows ( ROW_COUNT ) ;
158+ const rows = await result . resultSet . getRows ( this . prefetchRowCount ) ;
131159 if ( rows . length ) {
132160 return fetchAndConcat ( [ ...prevRows , ...rows ] ) ;
133161 }
0 commit comments