Skip to content

Commit 3284edf

Browse files
committed
Final set of test and document updates for all the new features
1 parent ed8c0ac commit 3284edf

15 files changed

+2113
-228
lines changed

doc/src/api_manual/connection.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,67 @@ Connection Methods
667667
* - Error ``error``
668668
- If ``createLob()`` succeeds, ``error`` is NULL. If an error occurs, then ``error`` contains the :ref:`error message <errorobj>`.
669669

670+
.. method:: connection.decodeOSON()
671+
672+
.. versionadded:: 6.4
673+
674+
.. code-block:: javascript
675+
676+
decodeOSON(Buffer buf);
677+
678+
This synchronous method decodes an OSON Buffer and returns a Javascript
679+
value. This method is useful for fetching BLOB columns that have the check
680+
constraint ``IS JSON FORMAT OSON`` enabled.
681+
682+
The parameters of the ``connection.decodeOSON()`` are:
683+
684+
.. list-table-with-summary:: connection.decodeOSON() Parameters
685+
:header-rows: 1
686+
:class: wy-table-responsive
687+
:align: center
688+
:widths: 10 10 30
689+
:summary: The first column displays the name of the parameter. The second column displays the data type of the parameter. The third column displays the description of the parameter.
690+
691+
* - Parameter
692+
- Data Type
693+
- Description
694+
* - ``buf``
695+
- Buffer
696+
- The OSON buffer that is to be decoded.
697+
698+
See :ref:`osontype` for an example.
699+
700+
.. method:: connection.encodeOSON()
701+
702+
.. versionadded:: 6.4
703+
704+
.. code-block:: javascript
705+
706+
encodeOSON(Any value);
707+
708+
This synchronous method encodes a JavaScript value to OSON bytes and
709+
returns a Buffer. This method is useful for inserting OSON bytes directly
710+
into BLOB columns that have the check constraint ``IS JSON FORMAT OSON``
711+
enabled.
712+
713+
The parameters of the ``connection.encodeOSON()`` are:
714+
715+
.. list-table-with-summary:: connection.encodeOSON() Parameters
716+
:header-rows: 1
717+
:class: wy-table-responsive
718+
:align: center
719+
:widths: 10 10 20
720+
:summary: The first column displays the name of the parameter. The second column displays the data type of the parameter. The third column displays the description of the parameter.
721+
722+
* - Parameter
723+
- Data Type
724+
- Description
725+
* - ``value``
726+
- Any
727+
- The JavaScript value that is to be encoded into OSON bytes. The JavaScript value can be any value supported by `JSON <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-FBC22D72-AA64-4B0A-92A2-837B32902E2C>`__.
728+
729+
See :ref:`osontype` for an example.
730+
670731
.. method:: connection.execute()
671732

672733
**Promise**::

doc/src/api_manual/lob.rst

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,61 @@ Lob Methods
161161

162162
**Promise**::
163163

164-
promise = getData();
164+
promise = getData(Number offset, Number amount);
165165

166-
Returns all the LOB data. CLOBs and NCLOBs will be returned as strings.
167-
BLOBs will be returned as a Buffer. This method is usable for LOBs up to
168-
1 GB in length.
166+
Returns a portion (or all) of the data in the LOB.
167+
168+
The parameters of ``lob.getData()`` are:
169+
170+
.. list-table-with-summary:: lob.getData() Parameters
171+
:header-rows: 1
172+
:class: wy-table-responsive
173+
:align: center
174+
:widths: 10 10 30
175+
:summary: The first column displays the name of the parameter. The second column displays the data type of the parameter. The third column displays the description of the parameter.
176+
177+
* - Parameter
178+
- Data Type
179+
- Description
180+
* - ``offset``
181+
- Number
182+
- For LOBs of type CLOB and NCLOB, the offset is the position from which the data is to be fetched, in `UCS-2 code points <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-42BCD57A-A380-4ED9-897F-0500A94803D1>`__. UCS-2 code points are equivalent to characters for all but supplemental characters. If supplemental characters are in the LOB, the offset and amount will have to be chosen carefully to avoid splitting a character.
183+
184+
For LOBs of type BLOB and BFILE, the offset is the position of the byte from which the data is to be fetched.
185+
186+
The default is *1*.
187+
188+
The value of ``offset`` must be greater than or equal to *1*.
189+
190+
If the ``offset`` specified in :meth:`lob.getData()` exceeds the length of the LOB, then the value *null* is returned.
191+
* - ``amount``
192+
- Number
193+
- For LOBs of type CLOB and NCLOB, the amount is the number of UCS-2 code points to be read from the absolute offset of the CLOB or NCLOB.
194+
195+
For LOBs of type BLOB and BFILE, the amount is the number of bytes to be read from the absolute offset of the BLOB or BFILE.
196+
197+
The default is the length of the LOB.
198+
199+
The value of ``amount`` must be greater than *0*.
200+
201+
If the ``amount`` specified in :meth:`lob.getData()` exceeds the length of the LOB, then only the data starting from the offset to the end of the LOB is returned.
202+
203+
If the ``amount`` specified in :meth:`lob.getData()` is *0*, then you will get the error ``NJS-005: invalid value for parameter 2``.
169204

170205
For queries returning LOB columns, it can be more efficient to use
171206
:attr:`~oracledb.fetchAsString`, :attr:`~oracledb.fetchAsBuffer`, or
172207
:ref:`fetchInfo <propexecfetchinfo>` instead of ``lob.getData()``.
173208

174209
Note that it is an asynchronous method and requires a round-trip to the
175-
database:
210+
database.
176211

177212
.. code-block:: javascript
178213
179-
const data = await myLob.getData();
214+
const data = await myLob.getData(offset, amount);
215+
216+
.. versionchanged:: 6.4
217+
218+
The ``offset`` and ``amount`` parameters were added.
180219

181220
**Callback**:
182221

doc/src/api_manual/oracledb.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,9 +3494,20 @@ node-oracledb, allowing use of new features.
34943494
specified when creating VARCHAR2 and LOB columns ensures that only JSON
34953495
data is stored in these columns.
34963496

3497+
Also, BLOB columns that were created with the ``IS JSON FORMAT OSON``
3498+
check constraint are fetched in the same way as
3499+
:ref:`columns of type JSON <json21fetch>` when this property is set to
3500+
*true*. The node-oracledb :ref:`Thick mode <enablingthick>` requires
3501+
Oracle Client 21c (or later).
3502+
34973503
The default value is *false*.
34983504

34993505
In a future version of node-oracledb, the setting of this attribute will
35003506
no longer be required since this will be the default behavior.
35013507

35023508
.. versionadded:: 6.3
3509+
3510+
.. versionchanged:: 6.4
3511+
3512+
BLOB columns with the ``IS JSON FORMAT OSON`` check constraint enabled
3513+
can now be fetched as JSON type columns when this property is set.

doc/src/release_notes.rst

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,31 @@ node-oracledb `v6.4.0 <https://github.com/oracle/node-oracledb/compare/v6.3.0...
1313
Common Changes
1414
++++++++++++++
1515

16-
#) Enhanced :meth:`~lob.getData` method to accept offset and amount arguments.
16+
#) Enhanced :meth:`lob.getData()` method to accept ``offset`` and ``amount``
17+
arguments.
1718
See `Issue #1643 <https://github.com/oracle/node-oracledb/issues/1643>`__.
1819

19-
#) Add support for fetching BLOB columns which have "IS JSON FORMAT OSON"
20-
constraint enabled in the same way as columns of type JSON.
21-
In node-oracledb :ref:`Thick mode <enablingthick>` this requires
22-
Oracle Client 21c or higher. Applications can get this new fetch behaviour
20+
#) Added support for fetching BLOB columns which have the
21+
``IS JSON FORMAT OSON`` constraint enabled in the same way as columns of
22+
type JSON. In node-oracledb :ref:`Thick mode <enablingthick>` this requires
23+
Oracle Client 21c or later. Applications can get this new fetch behaviour
2324
by setting the oracledb property :attr:`oracledb.future.oldJsonColumnAsObj`
2425
to `true`. The default value for this property is `false` which retains
2526
the existing fetch behaviour.
2627
In a future version, the new fetch behaviour will become default and
2728
setting this property will no longer be needed.
2829

29-
#) Added methods :meth:`~Connection.decodeOSON` and
30-
:meth:`~Connection.encodeOSON` to support fetching and inserting into
30+
#) Added methods :meth:`connection.decodeOSON()` and
31+
:meth:`connection.encodeOSON()` to support fetching and inserting into
3132
columns which have the check constraint ``IS JSON FORMAT OSON``
32-
enabled. Refer `Storing and Managing JSON Data <https://docs.oracle.com/en/database/oracle/oracle-database/19/adjsn/overview-of-storage-and-management-of-JSON-data.html#GUID-26AB85D2-3277-451B-BFAA-9DD45355FCC7>`__
33+
enabled. See :ref:`osontype` for more information.
3334

3435
#) Connections to standby database opened `MOUNTED` return
35-
`NAN <https://github.com/nodejs/nan>` for :meth:`~connection.maxOpenCursors`
36-
Fixed to return 0.
36+
`NAN <https://github.com/nodejs/nan>`__ for
37+
:attr:`connection.maxOpenCursors`. Fixed to return 0.
3738

38-
#) Added :meth:`~dbObject.toMap` method to :ref:`DbObject Class<dbobjectclass>`
39-
which returns a map object.
39+
#) Added :meth:`~dbObject.toMap()` method to
40+
:ref:`DbObject Class <dbobjectclass>` which returns a map object.
4041
See `Issue #1627 <https://github.com/oracle/node-oracledb/issues/1627>`__.
4142

4243
#) Added support to accept an object as an input parameter in the
@@ -46,18 +47,18 @@ Common Changes
4647
retrieve SQL string and bind values.
4748
See `Issue #1629 <https://github.com/oracle/node-oracledb/issues/1629>`__.
4849

49-
#) Added new extended :ref:`metadata <execmetadata>` information attribute
50+
#) Added a new extended :ref:`metadata <execmetadata>` information attribute
5051
``isOson`` for a fetched column.
5152

5253
#) Added :attr:`oracledb.poolPingTimeout` and :attr:`pool.poolPingTimeout`
53-
to limit the :meth:`connection.ping()` call time.
54+
properties to limit the :meth:`connection.ping()` call time.
5455
`Issue #1626 <https://github.com/oracle/node-oracledb/issues/1626>`__.
5556

5657
#) Added the :ref:`warning <execmanywarning>` property to the
5758
:ref:`result <resultobjproperties>` object of
5859
:meth:`connection.executeMany()`.
5960

60-
#) Attribute and element values of :ref:`DbObject Class
61+
#) The attribute and element values of :ref:`DbObject Class
6162
<dbobjectclass>` objects that contain strings or bytes now have their
6263
maximum size constraints checked. Errors ``NJS-142`` and ``NJS-143`` are
6364
now raised when the size constraints are violated.
@@ -74,20 +75,21 @@ Common Changes
7475
Thin Mode Changes
7576
++++++++++++++++++
7677

77-
#) Fix for the intermittent error ``NJS-103`` seen while fetching large number
78-
of CLOB columns whose metadata is split across multiple packets.
78+
#) Fixed the intermittent error ``NJS-103`` which was seen while fetching
79+
large number of CLOB columns whose metadata is split across multiple
80+
packets.
7981
`Issue #1642 <https://github.com/oracle/node-oracledb/issues/1642>`__.
8082

81-
#) Fixed potential cursor issues when using DRCP.
83+
#) Fixed potential cursor issues when using :ref:`DRCP <drcp>`.
8284

8385
#) Fixed bug in reading PLS_INTEGER type when used in PL/SQL records.
8486

8587
#) Error ``NJS-141: errors in array DML exceed 65535`` is now raised
8688
when the number of batch errors exceed 65535 when calling
8789
:meth:`connection.executeMany()` with the parameter ``batchErrors``
88-
set to the value `true`. Note that in thick mode, this error is not raised
89-
unless the number of batch errors is a multiple of 65536; instead,
90-
the number of batch errors returned is modulo 65536.
90+
set to the value `true`. Note that in node-oracledb Thick mode, this
91+
error is not raised unless the number of batch errors is a multiple of
92+
65536; instead, the number of batch errors returned is modulo 65536.
9193

9294
#) Updated connection pool to scan and remove idle connections from
9395
the beginning of the free connection list. This will ensure removal of all
@@ -100,9 +102,11 @@ Thin Mode Changes
100102
Thick Mode Changes
101103
++++++++++++++++++
102104

103-
#) Added support for asynchronous iteration of SODA document cursors.
105+
#) Added support for asynchronous iteration of
106+
:ref:`SODA document cursors <sodadocumentcursorclass>`.
104107

105-
#) Internal code and memory optimization changes for Advanced Queuing.
108+
#) Internal code and memory optimization changes for
109+
:ref:`Advanced Queuing <aq>`.
106110

107111
node-oracledb `v6.3.0 <https://github.com/oracle/node-oracledb/compare/v6.2.0...v6.3.0>`__ (21 Dec 2023)
108112
--------------------------------------------------------------------------------------------------------

doc/src/user_guide/json_data_type.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,93 @@ If you are using node-oracledb Thick mode, you must use Oracle Client 19c
148148
const r = await conn.execute(`SELECT po_document FROM j_purchaseorder`);
149149
console.dir(r.rows, { depth: null });
150150
151+
.. _osontype:
152+
153+
Using BLOB columns with OSON Storage Format in node-oracledb
154+
============================================================
155+
156+
You can use BLOB columns with Oracle's optimized binary storage format called
157+
`OSON <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-CBEDC779-
158+
39A3-43C9-AF38-861AE3FC0AEC>`__ if you want the fastest query and update
159+
performance. This OSON binary encoding format can be used with BLOB columns in
160+
both node-oracledb Thin or Thick modes. For Release 19c, BLOB with format OSON
161+
is supported only for Oracle Autonomous Databases. For Thick mode, you must
162+
additionally use Oracle Client 21c (or later).
163+
164+
To specify `OSON format for BLOB columns <https://docs.oracle.com/en/database/
165+
oracle/oracle-database/19/adjsn/overview-of-storage-and-management-of-JSON-
166+
data.html#GUID-26AB85D2-3277-451B-BFAA-9DD45355FCC7>`__, you can use the check
167+
constraint with the clause ``IS JSON FORMAT OSON`` when creating a table. This
168+
check constraint ensures that only binary encoded OSON data is stored in that
169+
column. For example, to create a table with a BLOB column containing OSON
170+
data:
171+
172+
.. code-block:: sql
173+
174+
CREATE TABLE my_table (oson_col BLOB CHECK (oson_col IS JSON FORMAT OSON));
175+
176+
**Inserting into BLOB columns with OSON Data**
177+
178+
To encode the Javascript value into OSON bytes, you can use the
179+
:meth:`connection.encodeOSON()` method. For example:
180+
181+
.. code-block:: javascript
182+
183+
const data = {key1: "val1"};
184+
// Generate OSON bytes
185+
const osonBytes = connection.encodeOSON(data);
186+
console.log(osonBytes);
187+
188+
This method returns a Buffer and prints an output such as::
189+
190+
<Buffer ff 4a 5a 01 21 02 01 00 05 00 0d 00 00 fa 00 00 04 6b 65 79 32 a4 01 01 00 00 00 07 33 04 76 61 6c 32>
191+
192+
To insert the OSON bytes into the table, you can use:
193+
194+
.. code-block:: javascript
195+
196+
// Insert the OSON bytes
197+
const result = await connection.execute(
198+
`INSERT INTO my_table (oson_col) VALUES (:1)`,
199+
[osonBytes]
200+
);
201+
202+
**Fetching BLOB Columns with OSON Data**
203+
204+
You can fetch BLOB columns which have the ``IS JSON FORMAT OSON`` check
205+
constraint enabled in the same way :ref:`JSON type columns <json21fetch>`
206+
are fetched when using Oracle Database 21c (or later). This can be done by
207+
setting :attr:`oracledb.future.oldJsonColumnAsObj` to the value *true* as
208+
shown below. If you are using node-oracledb Thick mode, you must use Oracle
209+
Client 21c (or later) for this setting to work. For example:
210+
211+
.. code-block:: javascript
212+
213+
oracledb.future.oldJsonColumnAsObj = true;
214+
const result = await connection.execute(`SELECT oson_col FROM my_table`);
215+
console.log(result.rows[0][0]);
216+
217+
This prints an output such as::
218+
219+
{key1: "val1"}
220+
221+
If you do not set the :attr:`oracledb.future.oldJsonColumnAsObj` to *true*,
222+
then you can fetch BLOB columns that contain OSON data as shown below:
223+
224+
.. code-block:: javascript
225+
226+
const result = await connection.execute(
227+
`SELECT json_object ('hello' value 'world' returning blob format oson
228+
) FROM dual`
229+
);
230+
const decodeOsonObj = connection.decodeOSON(result.rows[0][0]);
231+
console.log(decodeOsonObj);
232+
233+
The :meth:`connection.decodeOSON()` decodes the OSON Buffer and returns a
234+
Javascript value. This prints an ouput such as::
235+
236+
{ hello: 'world' }
237+
151238
IN Bind Type Mapping
152239
====================
153240

0 commit comments

Comments
 (0)