Skip to content

Commit 86b1c61

Browse files
committed
Documentation and Test case updates for the latest code changes
1 parent d045f4c commit 86b1c61

File tree

5 files changed

+203
-49
lines changed

5 files changed

+203
-49
lines changed

doc/src/api_manual/dbobject.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ The properties of a DbObject object are listed below.
9494
This read-only property is a string which identifies the name of the
9595
Oracle Database object or collection.
9696

97+
.. attribute:: dbObject.packageName
98+
99+
.. versionadded:: 6.2
100+
101+
This read-only property is a string which identifies the name of the
102+
package, if the type refers to a PL/SQL type. Otherwise, it returns
103+
*undefined*.
104+
97105
.. attribute:: dbObject.schema
98106

99107
This read-only property is a string which identifies the schema owning

doc/src/api_manual/sodacollection.rst

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,51 +52,18 @@ SodaCollection Methods
5252

5353
promise = createIndex(Object indexSpec);
5454

55-
Creates an index on a SODA collection, to improve the performance of
56-
SODA query-by-examples (QBE) or enable text searches. An index is
57-
defined by a specification, which is a JSON object that specifies how
58-
particular QBE patterns are to be indexed for quicker matching.
55+
Creates an index on a SODA collection, to improve the performance of SODA
56+
query-by-examples (QBE) or enable text searches. See :ref:`sodaindexes`
57+
for information on indexing.
5958

6059
Note that a commit should be performed before attempting to create an
6160
index.
6261

63-
Different index types can be used:
64-
65-
- B-tree: used to speed up query-by-example (QBE)
66-
:meth:`sodaOperation.filter()` searches.
67-
- JSON search: required for text searches using the ``$contains``
68-
operator in QBEs. Also improves QBE filter operation performance.
69-
Note a B-tree index will perform better for non-text searches.
70-
- GeoSpatial: for speeding up QBEs that do GeoJSON queries.
71-
7262
If :attr:`oracledb.autoCommit` is *true*, and ``createIndex()`` succeeds,
7363
then any open user transaction is committed.
7464
Note SODA DDL operations do not commit an open transaction the way that
7565
SQL always does for DDL statements.
7666

77-
See `Overview of SODA
78-
Indexing <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-
79-
4848E6A0-58A7-44FD-8D6D-A033D0CCF9CB>`__.
80-
81-
As an example, if a collection has these documents::
82-
83-
{"name": "Chris"}
84-
{"name": "Venkat"}
85-
{"name": "Srinath"}
86-
87-
Then a B-tree index could be created with:
88-
89-
.. code-block:: javascript
90-
91-
indexSpec = {name: "myIndex", fields: [{path: "name"}]};
92-
await collection.createIndex(indexSpec);
93-
94-
This index would improve the performance of QBEs like:
95-
96-
.. code-block:: javascript
97-
98-
d = await collection.find().filter({name: "Venkat"}).getOne();
99-
10067
The parameters of the ``sodaCollection.createIndex()`` method are:
10168

10269
.. _sodacollcreateindexparams:
@@ -140,6 +107,8 @@ SodaCollection Methods
140107
* - Error ``error``
141108
- If ``createIndex()`` succeeds, ``error`` is NULL. If an error occurs, then ``error`` contains the error message.
142109

110+
See :ref:`sodaindexes` for more information.
111+
143112
.. method:: sodaCollection.drop()
144113

145114
.. versionadded:: 3.0
@@ -276,6 +245,8 @@ SodaCollection Methods
276245
* - Object ``result``
277246
- If dropping the index succeeded, ``dropped`` will be *true*. If no index was found, ``dropped`` will be *false*.
278247

248+
See :ref:`sodaindexes` for an example.
249+
279250
.. method:: sodaCollection.find()
280251

281252
.. versionadded:: 3.0
@@ -302,6 +273,46 @@ SodaCollection Methods
302273
See :ref:`Simple Oracle Document Access (SODA) <sodaoverview>` for more
303274
examples.
304275

276+
.. method:: sodaCollection.listIndexes()
277+
278+
.. versionadded:: 6.2
279+
280+
**Promise:**::
281+
282+
promise = listIndexes();
283+
284+
Retrieves all the indexes from a SODA collection. This method returns an
285+
array of objects that contains the index specifications.
286+
287+
This method requires Oracle Client 21.3 or later (or Oracle Client 19 from
288+
19.13).
289+
290+
**Callback:**
291+
292+
If you are using the callback programming style::
293+
294+
listIndexes(function(Error error, Array listIndexes){});
295+
296+
The parameters of the callback function
297+
``function(Error error, Array listIndexes)`` are:
298+
299+
.. list-table-with-summary::
300+
:header-rows: 1
301+
:class: wy-table-responsive
302+
:align: center
303+
:widths: 15 30
304+
:summary: The first column displays the callback function parameter.
305+
The second column displays the description of the parameter.
306+
307+
* - Callback Function Parameter
308+
- Description
309+
* - Error ``error``
310+
- If ``listIndexes()`` succeeds, ``error`` is NULL. If an error occurs, then ``error`` contains the error message.
311+
* - Array ``listIndexes``
312+
- An array of objects, each containing the index specifications of the SODA collection.
313+
314+
See :ref:`Retrieving All Index Specifications <listindexes>` for an example.
315+
305316
.. _sodaoperationclass:
306317

307318
SodaOperation Class
@@ -481,8 +492,8 @@ with the key “c” is matched.
481492
If this method is specified in conjunction with a write operation, then
482493
this method is ignored.
483494

484-
This method is only supported in Oracle Client 21.3 and Oracle Client
485-
19.11 (or later).
495+
This method requires Oracle Client 21.3 or later (or Oracle Client 19 from
496+
19.11).
486497

487498
.. method:: sodaOperation.skip()
488499

doc/src/release_notes.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ For deprecated and desupported features, see :ref:`Deprecations and desupported
1010
node-oracledb `v6.2.0 <https://github.com/oracle/node-oracledb/compare/v6.1.0...v6.2.0>`__ (TBD)
1111
------------------------------------------------------------------------------------------------
1212

13+
Common Changes
14+
++++++++++++++
15+
16+
#) Added :attr:`~dbObject.packageName` property to
17+
:ref:`DbObject Class<dbobjectclass>`.
18+
1319
Thin Mode Changes
1420
++++++++++++++++++
1521

@@ -34,8 +40,6 @@ Thin Mode Changes
3440
Thick Mode Changes
3541
++++++++++++++++++
3642

37-
#) Added ``packageName`` attribute to :ref:`DbObject Class<dbobjectclass>`.
38-
3943
#) Added new property :ref:`binaryDir <odbinitoracleclientattrsopts>` to the
4044
options passed to :meth:`~oracledb.initOracleClient()` which indicates the
4145
name of the directory that contains the node-oracledb :ref:`Thick mode
@@ -46,8 +50,8 @@ Thick Mode Changes
4650
property. See `node-oracledb public Slack channel
4751
<https://node-oracledb.slack.com/ archives/CCM8AMSF7/p1694544451676639>`__.
4852

49-
#) Added ``listIndexes()`` method to fetch all the current indexes from
50-
a SODA collection.
53+
#) Added :meth:`sodaCollection.listIndexes()` method to fetch all the current
54+
indexes from a SODA collection.
5155

5256
#) Added :meth:`sodaOperation.lock()` method to disable modification of SODA
5357
documents by other connections.

doc/src/user_guide/soda.rst

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ Collections can be created like:
223223
}
224224
225225
This example creates a collection that, by default, allows JSON
226-
documents to be stored. A non-unique B-tree index is created on the
227-
``address.city`` path to improve search performance.
226+
documents to be stored. A non-unique :ref:`B-tree index <sodaindexes>` is
227+
created on the ``address.city`` path to improve search performance.
228228

229229
If the collection name passed to
230230
:meth:`sodaDatabase.createCollection()` already exists, it
@@ -244,7 +244,7 @@ metadata.
244244

245245
.. _accessingsodadocuments:
246246

247-
Creating and Accessing SODA documents
247+
Creating and Accessing SODA Documents
248248
=====================================
249249

250250
To insert a document into an opened collection, a JavaScript object that
@@ -558,6 +558,137 @@ Some QBE examples are:
558558
See `Overview of QBE Spatial Operators <https://www.oracle.com/pls/topic/
559559
lookup?ctx=dblatest&id=GUID-12994E27-DA98-40C7-8D4F-84341106F8D9>`__.
560560

561+
.. _sodaindexes:
562+
563+
Creating and Dropping SODA Indexes
564+
==================================
565+
566+
Indexing can improve the performance of SODA query-by-examples (QBE) or enable
567+
text searches. An index is defined by a specification, which is a JSON object
568+
that specifies how particular QBE patterns are to be indexed for quicker
569+
matching.
570+
571+
Note that a commit should be performed before attempting to create an
572+
index.
573+
574+
Each index specification is uniquely identified by the ``name`` field. The
575+
different index types that you can specify are:
576+
577+
- B-tree: Used to speed up query-by-example (QBE)
578+
:meth:`sodaOperation.filter()` searches. For this index type, you must
579+
specify the ``fields`` field in the index specification.
580+
581+
- GeoSpatial: Used for speeding up QBEs that do GeoJSON queries. For this
582+
index type, you must specify the ``spatial`` field in the index
583+
specification.
584+
585+
- JSON search: Required for text searches using the ``$contains``
586+
operator in QBEs. Also, improves QBE filter operation performance. For this
587+
index type, you must not specify the ``fields`` and ``spatial`` fields in
588+
the index specification. Note that a B-tree index will perform better for
589+
non-text searches.
590+
591+
See `Overview of SODA Indexing <https://www.oracle.com/pls/topic/lookup?ctx=
592+
dblatest&id=GUID-4848E6A0-58A7-44FD-8D6D-A033D0CCF9CB>`__.
593+
594+
As an example, if a collection has these documents::
595+
596+
{"name": "Chris"}
597+
{"name": "Venkat"}
598+
{"name": "Srinath"}
599+
600+
You must first specify the type of index that you want by creating a SODA
601+
index specification. For example, to create a B-tree index specification, you
602+
need to specify the ``fields`` field:
603+
604+
.. code-block:: javascript
605+
606+
indexSpec = {name: "myIndex", fields: [{path: "name"}]};
607+
608+
Then use that index specification to create the B-tree index using
609+
:meth:`sodaCollection.createIndex()`:
610+
611+
.. code-block:: javascript
612+
613+
await collection.createIndex(indexSpec);
614+
615+
This index would improve the performance of QBEs like:
616+
617+
.. code-block:: javascript
618+
619+
d = await collection.find().filter({name: "Venkat"}).getOne();
620+
621+
To drop a specific index on a SODA collection, use
622+
:meth:`sodaCollection.dropIndex()`:
623+
624+
.. code-block:: javascript
625+
626+
await collection.dropIndex("myIndex");
627+
628+
.. _listindexes:
629+
630+
Retrieving All Index Specifications in a Collection
631+
---------------------------------------------------
632+
633+
You can retrieve all the index specifications defined for the documents in a
634+
collection using :meth:`sodaCollection.listIndexes()`. For example:
635+
636+
.. code-block:: javascript
637+
638+
// Create a new SODA collection
639+
const collection = await soda.createCollection("mycollection");
640+
641+
// Create new index specifications
642+
const indexArr = [
643+
{
644+
"name": "HOME_IDX",
645+
"fields": [
646+
{
647+
"path": "home",
648+
"datatype": "string",
649+
"order": "asc"
650+
}
651+
]
652+
},
653+
{
654+
"name": "OFFICE_IDX",
655+
"fields": [
656+
{
657+
"path": "office",
658+
"datatype": "string",
659+
"order": "asc"
660+
}
661+
]
662+
}
663+
];
664+
665+
To create new indexes for each of the index specifications in ``IndexArr``:
666+
667+
.. code-block:: javascript
668+
669+
await collection.createIndex(indexArr[0]);
670+
await collection.createIndex(indexArr[1]);
671+
672+
To retrieve all the index specifications in the collection:
673+
674+
.. code-block:: javascript
675+
676+
// Retrieve list of indexes in a collection
677+
const fetchedIndexArr = await collection.listIndexes();
678+
679+
// Sort the index specification names in alphabetical order
680+
fetchedIndexArr.sort(function(a, b) {
681+
return a.name.localeCompare(b.name);
682+
});
683+
684+
console.log ("fetchIndexArr-0 " + JSON.stringify(fetchedIndexArr[0]));
685+
console.log ("fetchIndexArr-1 " + JSON.stringify(fetchedIndexArr[1]));
686+
687+
This prints an output such as::
688+
689+
fetchIndexArr-0 {"name":"HOME_IDX","schema":"SCOTT","tableName":"MYCOLLECTION","tableSchemaName":"SCOTT","indexNulls":false,"unique":false,"lax":false,"scalarRequired":false,"fields":[{"path":"home","dataType":"VARCHAR2","maxLength":2000,"order":"ASC"}]}
690+
fetchIndexArr-1 {"name":"OFFICE_IDX","schema":"SCOTT","tableName":"MYCOLLECTION","tableSchemaName":"SCOTT","indexNulls":false,"unique":false,"lax":false,"scalarRequired":false,"fields":[{"path":"office","dataType":"VARCHAR2","maxLength":2000,"order":"ASC"}]}
691+
561692
.. _sodatextsearches:
562693

563694
SODA Text Searches

test/currentSchema.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ describe('191. currentSchema.js', function() {
8383
}); // 191.2
8484

8585
it('191.3 Negative - can not set non-existent schema', async () => {
86-
86+
let conn;
8787
async function setInvalidSchema() {
88-
const conn = await oracledb.getConnection(dbConfig);
88+
conn = await oracledb.getConnection(dbConfig);
8989

9090
const schema = "foo";
9191
conn.currentSchema = schema;
92-
93-
await conn.close();
92+
await conn.execute('SELECT 1 FROM DUAL');
9493
}
9594

9695
await assert.rejects(
@@ -100,6 +99,7 @@ describe('191. currentSchema.js', function() {
10099
// ORA-01435: user does not exist
101100
// ORA-28726: set current schema operation failed
102101

102+
await conn.close();
103103
}); // 191.3
104104

105105
});

0 commit comments

Comments
 (0)