Skip to content

Commit 31d8cff

Browse files
committed
Allow DATE keys in Oracle Sharding support
1 parent 1d09d25 commit 31d8cff

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

doc/api.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,8 +2361,8 @@ Allows a connection to be established directly to a database shard. See
23612361
[Connecting to Sharded Databases](#sharding).
23622362

23632363
Array values may be of String type (mapping to VARCHAR2 sharding keys), Number
2364-
(NUMBER), or Buffer (RAW). Multiple types may be used in the array. Sharding
2365-
keys of DATE and TIMESTAMP types are not supported.
2364+
(NUMBER), Date (DATE), or Buffer (RAW). Multiple types may be used in the
2365+
array. Sharding keys TIMESTAMP type are not supported.
23662366

23672367
This property was added in node-oracledb 4.1.
23682368

@@ -2387,8 +2387,8 @@ Allows a connection to be established directly to a database shard. See
23872387
[Connecting to Sharded Databases](#sharding).
23882388

23892389
Array values may be of String type (mapping to VARCHAR2 sharding keys), Number
2390-
(NUMBER), or Buffer (RAW). Multiple types may be used in the array. Sharding
2391-
keys of DATE and TIMESTAMP types are not supported.
2390+
(NUMBER), Date (DATE), or Buffer (RAW). Multiple types may be used in the
2391+
array. Sharding keys TIMESTAMP type are not supported.
23922392

23932393
This property was added in node-oracledb 4.1.
23942394

@@ -8758,8 +8758,8 @@ key or super shard key is used.
87588758

87598759
The sharding and super sharding key properties are arrays of values. Array key
87608760
values may be of type String (mapping to VARCHAR2 sharding keys), Number
8761-
(NUMBER), or Buffer (RAW). Multiple types may be used in each array. Sharding
8762-
keys of DATE and TIMESTAMP types are not supported by node-oracledb.
8761+
(NUMBER), Date (DATE), or Buffer (RAW). Multiple types may be used in each
8762+
array. Sharding keys of TIMESTAMP type are not supported by node-oracledb.
87638763

87648764
For example, if sharding had been configured on a single column like:
87658765

@@ -8818,7 +8818,36 @@ const connection = await oracledb.getConnection(
88188818
});
88198819
```
88208820

8821-
To connect to shards when the sharding key is a RAW column like:
8821+
When the sharding key is a DATE column like:
8822+
8823+
```sql
8824+
CREATE SHARDED TABLE customers (
8825+
cust_id NUMBER,
8826+
cust_name VARCHAR2(30),
8827+
class VARCHAR2(10) NOT NULL,
8828+
signup_date DATE,
8829+
cust_code RAW(20),
8830+
CONSTRAINT signup_date_pk PRIMARY KEY(signup_date))
8831+
PARTITION BY CONSISTENT HASH (signup_date)
8832+
PARTITIONS AUTO TABLESPACE SET ts1;
8833+
```
8834+
8835+
then direct connection to a shard needs a Date key that is in the session time
8836+
zone. For example if the session time zone is set to UTC (see [Fetching Dates
8837+
and Timestamps](#datehandling)) then Dates must also be in UTC:
8838+
8839+
```javascript
8840+
key = new Date ("2019-11-30Z"); // when session time zone is UTC
8841+
const connection = await oracledb.getConnection(
8842+
{
8843+
user : "hr",
8844+
password : mypw, // mypw contains the hr schema password
8845+
connectString : "localhost/orclpdb1",
8846+
shardingkey : [key]
8847+
});
8848+
```
8849+
8850+
When the sharding key is a RAW column like:
88228851

88238852
```sql
88248853
CREATE SHARDED TABLE customers (
@@ -9343,6 +9372,16 @@ $ export ORA_SDTZ='UTC'
93439372
$ node myapp.js
93449373
```
93459374

9375+
If this variable is set in the application, it must be set before the first
9376+
connection is established:
9377+
9378+
```javascript
9379+
process.env.ORA_SDTZ = 'UTC';
9380+
9381+
const oracledb = require('oracledb');
9382+
const connection = await oracledb.getConnection(. . . );
9383+
```
9384+
93469385
The session time zone can also be changed at runtime for each
93479386
connection by executing:
93489387

0 commit comments

Comments
 (0)