Skip to content

Commit 5225c31

Browse files
committed
Add object example and update doc
1 parent 616d477 commit 5225c31

File tree

4 files changed

+229
-83
lines changed

4 files changed

+229
-83
lines changed

doc/api.md

Lines changed: 106 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ For installation information, see the [Node-oracledb Installation Instructions][
185185
- 4.2.7.4.3 [`outBinds`](#execmanyoutbinds)
186186
- 4.2.7.4.4 [`rowsAffected`](#execmanyrowsaffected)
187187
- 4.2.8 [`getDbObjectClass()`](#getdbobjectclass)
188-
- 4.2.9 [`getSodaDatabase()`](#getsodadatabase)
189-
- 4.2.10 [`getStatementInfo()`](#getstmtinfo)
190-
- 4.2.11 [`ping()`](#connectionping)
191-
- 4.2.12 [`queryStream()`](#querystream)
192-
- 4.2.13 [`getQueue()`](#getqueue)
188+
- 4.2.9 [`getQueue()`](#getqueue)
189+
- 4.2.10 [`getSodaDatabase()`](#getsodadatabase)
190+
- 4.2.11 [`getStatementInfo()`](#getstmtinfo)
191+
- 4.2.12 [`ping()`](#connectionping)
192+
- 4.2.13 [`queryStream()`](#querystream)
193193
- 4.2.14 [`release()`](#release)
194194
- 4.2.15 [`rollback()`](#rollback)
195195
- 4.2.16 [`subscribe()`](#consubscribe)
@@ -233,8 +233,9 @@ For installation information, see the [Node-oracledb Installation Instructions][
233233
- 6.1.4 [`elementTypeName`](#dbobjattributeselementtypename)
234234
- 6.1.5 [`fqn`](#dbobjattributesfqn)
235235
- 6.1.6 [`isCollection`](#dbobjattributesiscollection)
236-
- 6.1.7 [`name`](#dbobjattributesname)
237-
- 6.1.8 [`schema`](#dbobjattributesschema)
236+
- 6.1.7 [`length`](#dbobjattributeslength)
237+
- 6.1.8 [`name`](#dbobjattributesname)
238+
- 6.1.9 [`schema`](#dbobjattributesschema)
238239
- 6.2 [DbObject Methods](#dbobjectmethods)
239240
- 6.2.1 [DbObject Methods for Collections](#dbobjectmethodscolls)
240241
- [`append()`](#dbobjectmethodscolls), [`deleteElement()`](#dbobjectmethodscolls), [`getElement()`](#dbobjectmethodscolls),
@@ -3409,7 +3410,65 @@ This method was added in node-oracledb 4.0.
34093410
*Error error* | If `getDbObjectClass()` succeeds, `error` is NULL. If an error occurs, then `error` contains the [error message](#errorobj).
34103411
*DbObject obj* | A [DbObject](#dbobjectclass) representing an Oracle Database object or collection.
34113412
3412-
#### <a name="getsodadatabase"></a> 4.2.9 `connection.getSodaDatabase()`
3413+
#### <a name="getQueue"></a> 4.2.9 `connection.getQueue()`
3414+
3415+
##### Prototype
3416+
3417+
Callback:
3418+
```
3419+
getQueue(String name, [Object options,] function(Error error, AqQueue queue){})
3420+
```
3421+
3422+
Promise:
3423+
```
3424+
promise = getQueue(String name [, Object options])
3425+
```
3426+
3427+
##### Return Value
3428+
3429+
This method returns an [AqQueue Class](#aqqueueclass) object.
3430+
3431+
##### Description
3432+
3433+
This method returns a queue for enqueuing and dequeuing
3434+
[Oracle Advanced Queuing (AQ)](#aq) messages.
3435+
3436+
##### Parameters
3437+
3438+
- ```
3439+
String name
3440+
```
3441+
3442+
The name of the Advanced Queue to use. This queue should have
3443+
been created previously, for example with the
3444+
`DBMS_AQADM.CREATE_QUEUE()` function.
3445+
3446+
If the Advanced Queue does not exist in the database, an error will
3447+
occur when the queue is attempted to be used.
3448+
3449+
- ```
3450+
Object options
3451+
```
3452+
3453+
This optional argument can be used to specify the payload type.
3454+
It is an object with the following attributes:
3455+
3456+
Attribute Name | Description
3457+
---------------|-------------
3458+
`payloadType` | A string containing the name of an Oracle Database object type, or a [DbObject Class](#dbobjectclass) earlier acquired from [`connection.getDbObjectClass()`](#getdbobjectclass). If the name of an object type is used, it is recommended that a fully qualified name be used.
3459+
3460+
- ```
3461+
function(Error error, AqQueue queue)
3462+
```
3463+
3464+
The parameters of the callback function are:
3465+
3466+
Callback function parameter | Description
3467+
----------------------------|-------------
3468+
*Error error* | If `queue()` succeeds, `error` is NULL. If an error occurs, then `error` contains the [error message](#errorobj).
3469+
3470+
3471+
#### <a name="getsodadatabase"></a> 4.2.10 `connection.getSodaDatabase()`
34133472
34143473
##### Prototype
34153474
@@ -3437,7 +3496,7 @@ information about using SODA in node-oracledb.
34373496
34383497
This method was added in node-oracledb 3.0.
34393498
3440-
#### <a name="getstmtinfo"></a> 4.2.10 `connection.getStatementInfo()`
3499+
#### <a name="getstmtinfo"></a> 4.2.11 `connection.getStatementInfo()`
34413500
34423501
##### Prototype
34433502
@@ -3499,7 +3558,7 @@ This method was added in node-oracledb 2.2.
34993558
Statement Type Constants](#oracledbconstantsstmttype).
35003559
35013560
3502-
#### <a name="connectionping"></a> 4.2.11 `connection.ping()`
3561+
#### <a name="connectionping"></a> 4.2.12 `connection.ping()`
35033562
35043563
##### Prototype
35053564
@@ -3543,7 +3602,7 @@ This method was added in node-oracledb 2.2.
35433602
----------------------------|-------------
35443603
*Error error* | If `ping()` succeeds, `error` is NULL. If an error occurs, then `error` contains the [error message](#errorobj).
35453604
3546-
#### <a name="querystream"></a> 4.2.12 `connection.queryStream()`
3605+
#### <a name="querystream"></a> 4.2.13 `connection.queryStream()`
35473606
35483607
##### Prototype
35493608
@@ -3582,64 +3641,6 @@ This method was added in node-oracledb 1.8.
35823641
35833642
See [execute()](#execute).
35843643
3585-
#### <a name="getQueue"></a> 4.2.13 `connection.getQueue()`
3586-
3587-
##### Prototype
3588-
3589-
Callback:
3590-
```
3591-
getQueue(String name, [Object options,] function(Error error, AqQueue queue){})
3592-
```
3593-
3594-
Promise:
3595-
```
3596-
promise = getQueue(String name [, Object options])
3597-
```
3598-
3599-
##### Return Value
3600-
3601-
This method returns an [AqQueue Class](#aqqueueclass) object.
3602-
3603-
##### Description
3604-
3605-
This method returns a queue for enqueuing and dequeuing
3606-
[Oracle Advanced Queuing (AQ)](#aq) messages.
3607-
3608-
##### Parameters
3609-
3610-
- ```
3611-
String name
3612-
```
3613-
3614-
The name of the Advanced Queue to use. This queue should have
3615-
been created previously, for example with the
3616-
`DBMS_AQADM.CREATE_QUEUE()` function.
3617-
3618-
If the Advanced Queue does not exist in the database, an error will
3619-
occur when the queue is attempted to be used.
3620-
3621-
- ```
3622-
Object options
3623-
```
3624-
3625-
This optional argument can be used to specify the payload type.
3626-
It is an object with the following attributes:
3627-
3628-
Attribute Name | Description
3629-
---------------|-------------
3630-
`payloadType` | A string containing the name of an Oracle Database object type, or a [DbObject Class](#dbobjectclass) earlier acquired from [`connection.getDbObjectClass()`](#getdbobjectclass). If the name of an object type is used, it is recommended that a fully qualified name be used.
3631-
3632-
- ```
3633-
function(Error error, AqQueue queue)
3634-
```
3635-
3636-
The parameters of the callback function are:
3637-
3638-
Callback function parameter | Description
3639-
----------------------------|-------------
3640-
*Error error* | If `queue()` succeeds, `error` is NULL. If an error occurs, then `error` contains the [error message](#errorobj).
3641-
3642-
36433644
#### <a name="release"></a> 4.2.14 `connection.release()`
36443645
36453646
An alias for [connection.close()](#connectionclose).
@@ -4314,7 +4315,7 @@ semantics.
43144315
43154316
Each attribute will have an object that contains:
43164317
4317-
- `type`: the value of one of the [Oracle Database Type Constant](#oracledbconstantsdbtype), such as 2010 for `oracledb.DB_TYPE_NUMBER` and 2023 for `oracledb.DB_TYPE_OBJECT`.
4318+
- `type`: the value of one of the [Oracle Database Type Constants](#oracledbconstantsdbtype), such as 2010 for `oracledb.DB_TYPE_NUMBER` and 2023 for `oracledb.DB_TYPE_OBJECT`.
43184319
- `typeName`: a string corresponding to the type, such as "VARCHAR2" or "NUMBER". When the attribute is a DbObject, it will contain the name of the object.
43194320
- `typeClass`: set if the value of `type` is a DbObject. It is the DbObject class for the attribute.
43204321
@@ -4372,21 +4373,30 @@ readonly Boolean isCollection
43724373

43734374
This is *true* if the Oracle object is a collection, *false* otherwise.
43744375

4375-
#### <a name="dbobjattributesname"></a> 6.1.7 `dbObject.name`
4376+
#### <a name="dbobjattributeslength"></a> 6.1.7 `dbObject.length`
4377+
4378+
```
4379+
readonly Number length
4380+
```
4381+
4382+
When `dbObject.isCollection` is *true*, this will have the number of
4383+
elements in the collection. It is undefined for non-collections.
4384+
4385+
#### <a name="dbobjattributesname"></a> 6.1.8 `dbObject.name`
43764386

43774387
```
43784388
readonly String name
43794389
```
43804390

43814391
The name of the Oracle Database object or collection.
43824392

4383-
#### <a name="dbobjattributesschema"></a> 6.1.8 `dbObject.schema`
4393+
#### <a name="dbobjattributesschema"></a> 6.1.9 `dbObject.schema`
43844394

43854395
```
43864396
readonly String schema
43874397
```
43884398

4389-
The schema owning the Oracle Database object or collection.
4399+
The schema owning the Oracle Database object or collection.
43904400

43914401
### <a name="dbobjectmethods"></a> 6.2 DbObject Methods
43924402

@@ -4409,7 +4419,7 @@ Method Name | Description
44094419
`dbObject.getLastIndex()` | To obtain the last index for later use to obtain a value.
44104420
`dbObject.getNextIndex(Number index)` | Returns the next index value for later use to obtain a value.
44114421
`dbObject.getPrevIndex(Number index)` | Returns the previous index for later use to obtain the value.
4412-
`dbObject.hasElement()` | Returns *true* if any element exists in the collection. Returns *false* otherwise.
4422+
`dbObject.hasElement(Number index)` | Returns *true* if an element exists in the collection at the given index. Returns *false* otherwise.
44134423
`dbObject.setElement(Number index, value)` | To set the given value at the position of the given index.
44144424
`dbObject.getValues()` | Returns an array of element values as a JavaScript array in key order.
44154425
`dbObject.trim(count)` | Trims the specified number of elements from the end of the collection.
@@ -11007,12 +11017,13 @@ multiple hard-coded SQL statements, each with a different ORDER BY.
1100711017
1100811018
## <a name="objects"></a> 21. Oracle Database Objects and Collections
1100911019
11010-
You can query and insert most Oracle Database objects and collections.
11020+
You can query and insert most Oracle Database objects and collections,
11021+
with some [limitations](#objectlimitations).
1101111022
1101211023
### Inserting Objects
1101311024
1101411025
As an example, the Oracle Spatial type [SDO_GEOMETRY][139] can easily
11015-
be used in node-oracledb. Describinng SDO_GEOMETRY in SQL*Plus shows:
11026+
be used in node-oracledb. Describing SDO_GEOMETRY in SQL*Plus shows:
1101611027
1101711028
```
1101811029
Name Null? Type
@@ -11131,6 +11142,9 @@ await connection.execute(
1113111142
);
1113211143
```
1113311144
11145+
For objects that are nested, such as SDO_GEOMETRY is, you only need to
11146+
give the name of the top level object.
11147+
1113411148
See [selectgeometry.js][140] for a runnable example.
1113511149
1113611150
When handling multiple objects of the same type, then use fully
@@ -11320,11 +11334,19 @@ See [selectvarray.js][146] for a runnable example.
1132011334
### <a name="plsqlindexbybinds"></a> PL/SQL Collection Associative Arrays (Index-by)
1132111335
1132211336
Arrays of strings and numbers can be bound to PL/SQL IN, IN OUT, and
11323-
OUT parameters of PL/SQL INDEX BY associative array type. This type
11324-
was formerly called PL/SQL tables or index-by tables.
11337+
OUT parameters of PL/SQL INDEX BY associative array types with integer
11338+
keys. This Oracle type was formerly called PL/SQL tables or index-by
11339+
tables.
11340+
11341+
While you could bind associative arrays via named types as shown in
11342+
previous examples, it is generally more efficient to use the method
11343+
shown below.
1132511344
11326-
While you could access Associative Arrays via named types as shown in
11327-
previous examples, it is more efficient to use the method shown below.
11345+
Note that if you bind associative arrays via named types for BIND_IN,
11346+
then the resulting arrays in PL/SQL will start from index 0, which
11347+
affects FORALL usage. The method shown below results in indexes
11348+
starting from 1. (Using named type binding for nested tables and
11349+
VARRAYs does result in indexes starting from 1).
1132811350
1132911351
Given this table and PL/SQL package:
1133011352
@@ -11466,7 +11488,7 @@ See [plsqlarray.js][58] for a runnable example.
1146611488
You can use `executeMany()` with objects. See [Binding Objects with
1146711489
`executeMany()`](#executemanyobjects).
1146811490
11469-
### <a name="objectlimitations"></a> Oracle Database Type Limitations
11491+
### <a name="objectlimitations"></a> Oracle Database Object Type Limitations
1147011492
1147111493
PL/SQL collections and records can only be bound when both Oracle
1147211494
client libraries and Oracle Database are 12.1, or higher.
@@ -11477,6 +11499,8 @@ node-oracledb.
1147711499
1147811500
Subclasses of types are not supported.
1147911501
11502+
Oracle objects with REF references are not supported.
11503+
1148011504
Where there is no native support, use a PL/SQL wrapper that accepts
1148111505
types supported by node-oracledb and converts them to the required
1148211506
Oracle Database type.
@@ -12083,7 +12107,7 @@ There are runnable examples in the GitHub [examples][3] directory.
1208312107
1208412108
Oracle Advanced Queuing allows applications to use producer-consumer
1208512109
message passing. Queuing is highly configurable and scalable,
12086-
providing a great way to distribute workload. Messages can be queued
12110+
providing a great way to distribute workloads. Messages can be queued
1208712111
by multiple producers. Different consumers can filter messages for
1208812112
them. Messages can also be transformed or propagated to queues in
1208912113
other databases. Oracle AQ is available in all editions of the

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ plsqlarray.js | Examples of binding PL/SQL "INDEX BY" tables
9393
plsqlfunc.js | How to call a PL/SQL function
9494
plsqlproc.js | How to call a PL/SQL procedure
9595
plsqlrecord.js | Shows binding of PL/SQL RECORDS
96+
plsqlvarrayrecord.js | Shows binding a VARRAY of RECORD in PL/SQL
9697
raw1.js | Shows using a Buffer to insert and select a RAW
9798
refcursor.js | Shows using a ResultSet to fetch rows from a REF CURSOR
9899
refcursortoquerystream.js | Converts a REF CURSOR returned from `execute()` to a query stream.

0 commit comments

Comments
 (0)