Skip to content

Commit c2980cb

Browse files
committed
Added 'connectionString' as an alias for 'connectString' (Sagie Gur-Ari)
1 parent 2feec43 commit c2980cb

File tree

5 files changed

+180
-23
lines changed

5 files changed

+180
-23
lines changed

doc/api.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ limitations under the License.
6666
- 3.3.1.1 [`createPool()`: Parameters and Attributes](#createpoolpoolattrs)
6767
- 3.3.1.1.1 [`user`](#createpoolpoolattrsuser)
6868
- 3.3.1.1.2 [`password`](#createpoolpoolattrspassword)
69-
- 3.3.1.1.3 [`connectString`](#createpoolpoolattrsconnectstring)
69+
- 3.3.1.1.3 [`connectString`](#createpoolpoolattrsconnectstring), [`connectionString`](#createpoolpoolattrsconnectstring)
7070
- 3.3.1.1.4 [`externalAuth`](#createpoolpoolattrsexternalauth)
7171
- 3.3.1.1.5 [`stmtCacheSize`](#createpoolpoolattrsstmtcachesize)
7272
- 3.3.1.1.6 [`poolAlias`](#createpoolpoolattrspoolalias)
@@ -84,7 +84,7 @@ limitations under the License.
8484
- 3.3.2.1.2 [Connection Attributes](#getconnectiondbattrsconnattrs)
8585
- 3.3.2.1.2.1 [`user`](#getconnectiondbattrsuser)
8686
- 3.3.2.1.2.2 [`password`](#getconnectiondbattrspassword)
87-
- 3.3.2.1.2.3 [`connectString`](#getconnectiondbattrsconnectstring)
87+
- 3.3.2.1.2.3 [`connectString`](#getconnectiondbattrsconnectstring), [`connectionString`](#getconnectiondbattrsconnectstring)
8888
- 3.3.2.1.2.4 [`privilege`](#getconnectiondbattrsprivilege)
8989
- 3.3.2.1.2.5 [`externalAuth`](#getconnectiondbattrsexternalauth)
9090
- 3.3.2.1.2.6 [`stmtCacheSize`](#getconnectiondbattrsstmtcachesize)
@@ -1235,6 +1235,8 @@ See [Connection Pool Cache](#connpoolcache) for more details.
12351235
A pool should be terminated with the [`pool.close()`](#poolclose)
12361236
call, but only after all connections have been released.
12371237

1238+
See [Connection Pooling](#connpooling) for more information about pooling.
1239+
12381240
###### <a name="createpoolpoolattrs"></a> 3.3.1.1 `createPool()`: Parameters and Attributes
12391241

12401242
```
@@ -1277,12 +1279,15 @@ String password
12771279
The password of the database user. A password is also necessary if a
12781280
proxy user is specified.
12791281

1280-
###### <a name="createpoolpoolattrsconnectstring"></a> 3.3.1.1.3 `connectString`
1282+
###### <a name="createpoolpoolattrsconnectstring"></a> 3.3.1.1.3 `connectString`, `connectionString`
12811283

12821284
```
12831285
String connectString
1286+
String connectionString
12841287
```
12851288

1289+
The two properties are aliases for each other. Use only one of the properties.
1290+
12861291
The Oracle database instance to connect to. The string can be an Easy
12871292
Connect string, or a Net Service Name from a `tnsnames.ora` file, or the
12881293
name of a local Oracle database instance. See
@@ -1362,6 +1367,13 @@ The default value is 4.
13621367
This optional property overrides the
13631368
[`oracledb.poolMax`](#propdbpoolmax) property.
13641369

1370+
See [Connections and Number of Threads](#numberofthreads) for why you
1371+
should not increase this value beyond 128. Importantly, if you
1372+
increase `poolMax` you should also increase the number of threads
1373+
available to node-oracledb.
1374+
1375+
See [Connection Pooling](#connpooling) for other pool sizing guidelines.
1376+
13651377
###### <a name="createpoolpoolattrspoolmin"></a> 3.3.1.1.9 `poolMin`
13661378

13671379
```
@@ -1545,12 +1557,15 @@ String password
15451557
The password of the database user. A password is also necessary if a
15461558
proxy user is specified.
15471559

1548-
###### <a name="getconnectiondbattrsconnectstring"></a> 3.3.2.1.2.3 `connectString`
1560+
###### <a name="getconnectiondbattrsconnectstring"></a> 3.3.2.1.2.3 `connectString`, `connectionString`
15491561

15501562
```
15511563
String connectString
1564+
String connectionString
15521565
```
15531566

1567+
The two properties are aliases for each other. Use only one of the properties.
1568+
15541569
The Oracle database instance to connect to. The string can be an Easy Connect string, or a
15551570
Net Service Name from a `tnsnames.ora` file, or the name of a local
15561571
Oracle database instance. See
@@ -2798,8 +2813,11 @@ Connect](#easyconnect) string, or a Net Service Name from a local
27982813
[`tnsnames.ora`](#tnsnames) file or external naming service, or it can
27992814
be the SID of a local Oracle database instance.
28002815

2801-
If `connectString` is not specified, the empty string "" is used which
2802-
indicates to connect to the local, default database.
2816+
The `connectionString` property is an aliases for `connectString`.
2817+
Use only one of the properties.
2818+
2819+
If a connect string is not specified, the empty string "" is used
2820+
which indicates to connect to the local, default database.
28032821

28042822
#### <a name="easyconnect"></a> 8.1.1 Easy Connect Syntax for Connection Strings
28052823

@@ -3408,7 +3426,7 @@ To use DRCP in node-oracledb:
34083426
34093427
1. The DRCP pool must be started in the database: `SQL> execute dbms_connection_pool.start_pool();`
34103428
2. The [`connectionClass`](#propdbconclass) should be set by the node-oracledb application. If it is not set, the pooled server session memory will not be reused optimally, and the statistic views will record large values for `NUM_MISSES`.
3411-
3. The `getConnection()` property `connectString` must specify to use a pooled server, either by the Easy Connect syntax like [`myhost/sales:POOLED`](#easyconnect), or by using a [`tnsnames.ora`](#tnsnames) alias for a connection that contains `(SERVER=POOLED)`.
3429+
3. The `pool.createPool()` or `oracledb.getConnection()` property `connectString` (or its alias `connectionString`) must specify to use a pooled server, either by the Easy Connect syntax like [`myhost/sales:POOLED`](#easyconnect), or by using a [`tnsnames.ora`](#tnsnames) alias for a connection that contains `(SERVER=POOLED)`.
34123430
34133431
For efficiency, it is recommended that DRCP connections should be used
34143432
with node-oracledb's local [connection pool](#poolclass).

lib/oracledb.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -139,6 +139,11 @@ function createPool(poolAttrs, createPoolCb) {
139139
nodbUtil.assert(nodbUtil.isObject(poolAttrs), 'NJS-006', 1);
140140
nodbUtil.assert(typeof createPoolCb === 'function', 'NJS-006', 2);
141141

142+
// Allow user to use connectionString as an alias for connectString.
143+
if (poolAttrs.connectString === undefined) {
144+
poolAttrs.connectString = poolAttrs.connectionString;
145+
}
146+
142147
// Additional validations should pass errors via the callback. Need to ensure
143148
// that errors are raised prior to actually creating the pool via _createPool.
144149
if (poolAttrs.poolAlias !== undefined) {
@@ -277,6 +282,11 @@ function getConnection(a1, a2) {
277282

278283
pool.getConnection(getConnectionCb);
279284
} else {
285+
// Allow user to use connectionString as an alias for connectString.
286+
if (connAttrs.connectString === undefined) {
287+
connAttrs.connectString = connAttrs.connectionString;
288+
}
289+
280290
self._getConnection(connAttrs, function(err, connInst) {
281291
if (err) {
282292
getConnectionCb(err);

test/connection.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -744,7 +744,7 @@ describe('1. connection.js', function(){
744744
});
745745
});
746746
});
747-
}); // 1.7
747+
}); // 1.6
748748

749749
describe('1.7 invalid credentials', function() {
750750

@@ -766,6 +766,63 @@ describe('1. connection.js', function(){
766766

767767
});
768768

769-
});
769+
}); // 1.7
770+
771+
describe('1.8 connectionString alias', function() {
772+
it('1.8.1 allows connectionString to be used as an alias for connectString', function(done) {
773+
oracledb.getConnection(
774+
{
775+
user: dbConfig.user,
776+
password: dbConfig.password,
777+
connectionString: dbConfig.connectString
778+
},
779+
function(err, connection) {
780+
should.not.exist(err);
781+
782+
connection.should.be.ok();
783+
784+
connection.close(function(err) {
785+
should.not.exist(err);
786+
787+
done();
788+
});
789+
}
790+
);
791+
});
792+
793+
it('1.8.2 favors connectString if both connectString and connectionString are passed', function(done) {
794+
oracledb.getConnection(
795+
{
796+
user: dbConfig.user,
797+
password: dbConfig.password,
798+
connectString: 'this is wrong',
799+
connectionString: dbConfig.connectString
800+
},
801+
function(err, connection) {
802+
should.exist(err);
803+
804+
oracledb.getConnection(
805+
{
806+
user: dbConfig.user,
807+
password: dbConfig.password,
808+
connectString: dbConfig.connectString,
809+
connectionString: 'this is wrong'
810+
},
811+
function(err, connection) {
812+
should.not.exist(err);
813+
814+
connection.should.be.ok();
815+
816+
connection.close(function(err) {
817+
should.not.exist(err);
818+
819+
done();
820+
});
821+
}
822+
);
823+
}
824+
);
825+
});
826+
}); // 1.8
770827

771828
});

test/list.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Overview of node-oracledb functional tests
2525
1.6.1 close can be used as an alternative to release
2626
1.7 invalid credentials
2727
1.7.1 cannot get connections with invalid credentials
28+
1.8 connectionString alias
29+
1.8.1 allows connectionString to be used as an alias for connectString
30+
1.8.2 favors connectString if both connectString and connectionString are passed
2831

2932
2. pool.js
3033
2.1 default values
@@ -68,6 +71,9 @@ Overview of node-oracledb functional tests
6871
2.11 Invalid Credential
6972
2.11.1 error occurs at creating pool when poolMin >= 1
7073
2.11.2 error occurs at getConnection() when poolMin is the default value 1
74+
2.12 connectionString alias
75+
2.12.1 allows connectionString to be used as an alias for connectString
76+
2.12.2 favors connectString if both connectString and connectionString are passed
7177

7278
3. examples.js
7379
3.1 connect.js
@@ -3796,7 +3802,7 @@ Overview of node-oracledb functional tests
37963802

37973803
150. fetchArraySize3.js
37983804
150.1 DML binding
3799-
150.1.1 oracledb.fetchArraySize = 1
3805+
150.1.1 oracledb.fetchArraySize = 1
38003806
150.1.2 oracledb.fetchArraySize = tableSize/20
38013807
150.1.3 oracledb.fetchArraySize = tableSize/10
38023808
150.1.4 oracledb.fetchArraySize = tableSize
@@ -3807,7 +3813,7 @@ Overview of node-oracledb functional tests
38073813
150.2.3 Bind OUT with oracledb.fetchArraySize = tableSize/10
38083814
150.2.4 Bind OUT with oracledb.fetchArraySize = tableSize
38093815
150.2.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)
3810-
150.2.6 Bind IN OUT with oracledb.fetchArraySize = 1
3816+
150.2.6 Bind IN OUT with oracledb.fetchArraySize = 1
38113817
150.2.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20
38123818
150.2.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10
38133819
150.2.9 Bind IN OUT with oracledb.fetchArraySize = tableSize
@@ -3818,15 +3824,15 @@ Overview of node-oracledb functional tests
38183824
150.3.3 Bind OUT with oracledb.fetchArraySize = tableSize/10
38193825
150.3.4 Bind OUT with oracledb.fetchArraySize = tableSize
38203826
150.3.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)
3821-
150.3.6 Bind IN OUT with oracledb.fetchArraySize = 1
3827+
150.3.6 Bind IN OUT with oracledb.fetchArraySize = 1
38223828
150.3.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20
38233829
150.3.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10
38243830
150.3.9 Bind IN OUT with oracledb.fetchArraySize = tableSize
38253831
150.3.10 Bind IN OUT with oracledb.fetchArraySize = (table size - 1)
38263832

38273833
151. fetchArraySize4.js
38283834
151.1 getRows() of resultSet = true
3829-
151.1.1 numRows > table size > oracledb.fetchArraySize
3835+
151.1.1 numRows > table size > oracledb.fetchArraySize
38303836
151.1.2 numRows > oracledb.fetchArraySize > table size
38313837
151.1.3 table size > numRows > oracledb.fetchArraySize
38323838
151.1.4 table size > oracledb.fetchArraySize > maxRow
@@ -3839,7 +3845,7 @@ Overview of node-oracledb functional tests
38393845
151.1.11 numRows = (table size - 1), fetchArraySize = table size
38403846
151.1.12 fetchArraySize = (table size - 1), numRows = table size
38413847
151.2 getRow() of resultSet = true
3842-
151.2.1 oracledb.fetchArraySize = 1
3848+
151.2.1 oracledb.fetchArraySize = 1
38433849
151.2.2 oracledb.fetchArraySize = tableSize/50
38443850
151.2.3 oracledb.fetchArraySize = tableSize/20
38453851
151.2.4 oracledb.fetchArraySize = tableSize/10
@@ -3900,7 +3906,7 @@ Overview of node-oracledb functional tests
39003906

39013907
153. fetchArraySize6.js
39023908
153.1 DML binding
3903-
153.1.1 fetchArraySize = 1
3909+
153.1.1 fetchArraySize = 1
39043910
153.1.2 fetchArraySize = tableSize/20
39053911
153.1.3 fetchArraySize = tableSize/10
39063912
153.1.4 fetchArraySize = tableSize
@@ -3911,7 +3917,7 @@ Overview of node-oracledb functional tests
39113917
153.2.3 Bind OUT with fetchArraySize = tableSize/10
39123918
153.2.4 Bind OUT with fetchArraySize = tableSize
39133919
153.2.5 Bind OUT with fetchArraySize = (table size - 1)
3914-
153.2.6 Bind IN OUT with fetchArraySize = 1
3920+
153.2.6 Bind IN OUT with fetchArraySize = 1
39153921
153.2.7 Bind IN OUT with fetchArraySize = tableSize/20
39163922
153.2.8 Bind IN OUT with fetchArraySize = tableSize/10
39173923
153.2.9 Bind IN OUT with fetchArraySize = tableSize
@@ -3922,15 +3928,15 @@ Overview of node-oracledb functional tests
39223928
153.3.3 Bind OUT with fetchArraySize = tableSize/10
39233929
153.3.4 Bind OUT with fetchArraySize = tableSize
39243930
153.3.5 Bind OUT with fetchArraySize = (table size - 1)
3925-
153.3.6 Bind IN OUT with fetchArraySize = 1
3931+
153.3.6 Bind IN OUT with fetchArraySize = 1
39263932
153.3.7 Bind IN OUT with fetchArraySize = tableSize/20
39273933
153.3.8 Bind IN OUT with fetchArraySize = tableSize/10
39283934
153.3.9 Bind IN OUT with fetchArraySize = tableSize
39293935
153.3.10 Bind IN OUT with fetchArraySize = (table size - 1)
3930-
3936+
39313937
154. fetchArraySize7.js
39323938
154.1 getRows() of resultSet = true
3933-
154.1.1 numRows > table size > fetchArraySize
3939+
154.1.1 numRows > table size > fetchArraySize
39343940
154.1.2 numRows > fetchArraySize > table size
39353941
154.1.3 table size > numRows > fetchArraySize
39363942
154.1.4 table size > fetchArraySize > maxRow
@@ -3943,7 +3949,7 @@ Overview of node-oracledb functional tests
39433949
154.1.11 numRows = (table size - 1), fetchArraySize = table size
39443950
154.1.12 fetchArraySize = (table size - 1), numRows = table size
39453951
154.2 getRow() of resultSet = true
3946-
154.2.1 fetchArraySize = 1
3952+
154.2.1 fetchArraySize = 1
39473953
154.2.2 fetchArraySize = tableSize/50
39483954
154.2.3 fetchArraySize = tableSize/20
39493955
154.2.4 fetchArraySize = tableSize/10

test/pool.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -1037,4 +1037,70 @@ describe('2. pool.js', function() {
10371037

10381038
}); // 2.11
10391039

1040+
describe('2.12 connectionString alias', function() {
1041+
it('2.12.1 allows connectionString to be used as an alias for connectString', function(done) {
1042+
oracledb.createPool(
1043+
{
1044+
user: dbConfig.user,
1045+
password: dbConfig.password,
1046+
connectionString: dbConfig.connectString,
1047+
poolMin: 1,
1048+
poolMax: 1,
1049+
poolIncrement: 0
1050+
},
1051+
function(err, pool) {
1052+
should.not.exist(err);
1053+
1054+
pool.should.be.ok();
1055+
1056+
pool.close(function(err) {
1057+
should.not.exist(err);
1058+
1059+
done();
1060+
});
1061+
}
1062+
);
1063+
});
1064+
1065+
it('2.12.2 favors connectString if both connectString and connectionString are passed', function(done) {
1066+
oracledb.createPool(
1067+
{
1068+
user: dbConfig.user,
1069+
password: dbConfig.password,
1070+
connectString: 'this is wrong',
1071+
connectionString: dbConfig.connectString,
1072+
poolMin: 1,
1073+
poolMax: 1,
1074+
poolIncrement: 0
1075+
},
1076+
function(err, pool) {
1077+
should.exist(err);
1078+
1079+
oracledb.createPool(
1080+
{
1081+
user: dbConfig.user,
1082+
password: dbConfig.password,
1083+
connectString: dbConfig.connectString,
1084+
connectionString: 'this is wrong',
1085+
poolMin: 1,
1086+
poolMax: 1,
1087+
poolIncrement: 0
1088+
},
1089+
function(err, pool) {
1090+
should.not.exist(err);
1091+
1092+
pool.should.be.ok();
1093+
1094+
pool.close(function(err) {
1095+
should.not.exist(err);
1096+
1097+
done();
1098+
});
1099+
}
1100+
);
1101+
}
1102+
);
1103+
});
1104+
}); // 2.12
1105+
10401106
});

0 commit comments

Comments
 (0)