Skip to content

Commit 2469fb2

Browse files
committed
Documentation and test case updates for recent enhancements
1 parent 47a883c commit 2469fb2

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

doc/src/api_manual/connection.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ Connection Methods
897897
- BINARY_INTEGER
898898
- ``oracledb.DB_TYPE_BINARY_INTEGER``
899899
- This combination is supported from node-oracledb 4.2. Only supported for PL/SQL binds.
900+
* - BigInt
901+
- NUMBER
902+
- ``oracledb.DB_TYPE_NUMBER``
903+
- This combination is supported from node-oracledb 6.5.
900904
* - Date
901905
- DATE
902906
- ``oracledb.DB_TYPE_DATE``

doc/src/user_guide/bind.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ zone, or to the time zone specified for TIMESTAMP WITH TIME ZONE columns.
175175
If later queried, they are returned in the session time zone. See
176176
:ref:`Fetching Date and Timestamps <datehandling>` for more information.
177177

178+
The binding of BigInt values was introduced in node-oracledb 6.5. When binding
179+
a JavaScript BigInt value in an ``INSERT`` statement, the bind ``type`` used by
180+
default is ``oracledb.DB_TYPE_NUMBER``. For example:
181+
182+
.. code-block:: javascript
183+
184+
const result = await connection.execute(
185+
`INSERT INTO employees (id) VALUES (:1)`,
186+
[98765432123456n]
187+
);
188+
189+
For information on fetching BigInt numbers, see this
190+
:ref:`section <biginthandling>`.
191+
178192
.. _outbind:
179193

180194
OUT and IN OUT Bind Parameters

doc/src/user_guide/sql_execution.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,50 @@ string to a floating point number.
899899
See `examples/typehandlernum.js <https://github.com/oracle/node-oracledb/tree/
900900
main/examples/typehandlernum.js>`__ for a runnable example.
901901

902+
.. _biginthandling:
903+
904+
Fetching BigInt Numbers
905+
+++++++++++++++++++++++
906+
907+
BigInt is a numerical JavaScript data type to represent integer values that
908+
are larger than the range supported by the Number data type. BigInt values can
909+
be created by appending 'n' to the end of integer values or by calling the
910+
``BigInt()`` function. For example, 123n, -123n, 1_000_000_001n,
911+
9876543321n, or BigInt(9876543321). See :ref:`binddatatypenotes` for
912+
information on binding BigInt values.
913+
914+
By default, BigInt numbers fetched from the database are returned as
915+
JavaScript numbers as shown below.
916+
917+
.. code-block:: javascript
918+
919+
const sql = `SELECT id FROM employees WHERE id = :1`;
920+
const binds = [ 98765432123456n ];
921+
const result = await connection.execute(sql, binds);
922+
console.log(result.rows[0]);
923+
924+
This query prints ``98765432123456``.
925+
926+
To reliably work with BigInt numbers, it is recommended to use a
927+
:ref:`fetch type handler <fetchtypehandler>`. The following fetch type handler
928+
can be used with the example above to return the correct BigInt value:
929+
930+
.. code-block:: javascript
931+
932+
// Tells the driver to return the number as a BigInt value
933+
const myfetchTypeHandler = function() {
934+
return {
935+
converter: (val) => val === null ? null : BigInt(val)
936+
};
937+
};
938+
oracledb.fetchTypeHandler = myfetchTypeHandler;
939+
940+
With this fetch type handler, the query would print ``98765432123456n``.
941+
942+
Without a fetch type handler, fetching a very large or a very small BigInt
943+
number that is not supported by the application platform will result in
944+
truncation to the maximum and the minimum integer values respectively.
945+
902946
.. _datehandling:
903947

904948
Fetching Dates and Timestamps

test/bigInt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('300. bigInt.js', function() {
9191

9292
it('300.2.2 use fetchTypeHandler to get BigInt value', async function() {
9393
const myFetchTypeHandler = function() {
94-
return {converter: (val) => BigInt(val)};
94+
return {converter: (val) => val === null ? null : BigInt(val)};
9595
};
9696

9797
oracledb.fetchTypeHandler = myFetchTypeHandler;

0 commit comments

Comments
 (0)