Skip to content

Commit dc208c9

Browse files
committed
Add listIndex() method of SODA collection object to fetch all indexes in a SODA collection
1 parent f0650d9 commit dc208c9

File tree

8 files changed

+350
-1
lines changed

8 files changed

+350
-1
lines changed

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Thin Mode Changes
2828
Thick Mode Changes
2929
++++++++++++++++++
3030

31+
#) Implemented enhancement to support listIndexes() method to fetch all the
32+
current indexes from the SODA collection.
33+
3134
#) Fixed bug where a segmentation fault (segfault) occurred while populating
3235
object Collection having BLOB property. See
3336
`node-oracledb public Slack channel <https://node-oracledb.slack.com/
@@ -38,6 +41,7 @@ Thick Mode Changes
3841
on any SODA document. An explicit commit or rollback is required to unlock
3942
and modify any corresponding SODA document.
4043

44+
4145
#) Fixed bug that throws an 'ORA-21525' error with dbObjects having one or
4246
more 'Number' attributes of precision less than or equal to 18 and scale
4347
as 0.

lib/sodaCollection.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ class SodaCollection {
188188
return doc;
189189
}
190190

191+
//---------------------------------------------------------------------------
192+
// listIndexes()
193+
//
194+
// To obtain all indices from the collection
195+
//---------------------------------------------------------------------------
196+
async listIndexes() {
197+
const arr = await this._impl.listIndexes();
198+
return arr.map(i => JSON.parse(i));
199+
}
200+
191201
//---------------------------------------------------------------------------
192202
// metaData()
193203
//
@@ -262,6 +272,7 @@ nodbUtil.wrapFns(SodaCollection.prototype,
262272
"insertManyAndGet",
263273
"insertOne",
264274
"insertOneAndGet",
275+
"listIndexes",
265276
"save",
266277
"saveAndGet",
267278
"truncate");

src/njsBaton.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ void njsBaton_free(njsBaton *baton, napi_env env)
228228
baton->sodaCollNames);
229229
NJS_FREE_AND_CLEAR(baton->sodaCollNames);
230230
}
231+
if (baton->indexList) {
232+
dpiContext_freeStringList(baton->globals->context, baton->indexList);
233+
NJS_FREE_AND_CLEAR(baton->indexList);
234+
}
235+
231236
if (!baton->jsBufferRef) {
232237
NJS_FREE_AND_CLEAR(baton->bufferPtr);
233238
}

src/njsModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ struct njsBaton {
333333
uint32_t *bindNameLengths;
334334
dpiSodaOperOptions *sodaOperOptions;
335335
dpiStringList *sodaCollNames;
336+
dpiStringList *indexList;
336337
njsLobBuffer *lob;
337338

338339
// ODPI-C handles (requires release)

src/njsSodaCollection.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_insertMany);
4444
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_insertManyAndGet);
4545
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_insertOne);
4646
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_insertOneAndGet);
47+
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_listIndexes);
4748
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_save);
4849
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_saveAndGet);
4950
NJS_NAPI_METHOD_DECL_ASYNC(njsSodaCollection_truncate);
@@ -57,6 +58,7 @@ static NJS_ASYNC_METHOD(njsSodaCollection_insertManyAsync);
5758
static NJS_ASYNC_METHOD(njsSodaCollection_insertManyAndGetAsync);
5859
static NJS_ASYNC_METHOD(njsSodaCollection_insertOneAsync);
5960
static NJS_ASYNC_METHOD(njsSodaCollection_insertOneAndGetAsync);
61+
static NJS_ASYNC_METHOD(njsSodaCollection_listIndexesAsync);
6062
static NJS_ASYNC_METHOD(njsSodaCollection_saveAsync);
6163
static NJS_ASYNC_METHOD(njsSodaCollection_saveAndGetAsync);
6264
static NJS_ASYNC_METHOD(njsSodaCollection_truncateAsync);
@@ -67,6 +69,7 @@ static NJS_ASYNC_POST_METHOD(njsSodaCollection_dropIndexPostAsync);
6769
static NJS_ASYNC_POST_METHOD(njsSodaCollection_getDataGuidePostAsync);
6870
static NJS_ASYNC_POST_METHOD(njsSodaCollection_insertManyAndGetPostAsync);
6971
static NJS_ASYNC_POST_METHOD(njsSodaCollection_insertOneAndGetPostAsync);
72+
static NJS_ASYNC_POST_METHOD(njsSodaCollection_listIndexesPostAsync);
7073
static NJS_ASYNC_POST_METHOD(njsSodaCollection_saveAndGetPostAsync);
7174

7275
// processing arguments methods
@@ -99,6 +102,8 @@ static const napi_property_descriptor njsClassProperties[] = {
99102
napi_default, NULL },
100103
{ "getName", NULL, njsSodaCollection_getName, NULL, NULL, NULL,
101104
napi_default, NULL },
105+
{ "listIndexes", NULL, njsSodaCollection_listIndexes, NULL, NULL, NULL,
106+
napi_default, NULL },
102107
{ "save", NULL, njsSodaCollection_save, NULL, NULL, NULL, napi_default,
103108
NULL },
104109
{ "saveAndGet", NULL, njsSodaCollection_saveAndGet, NULL, NULL, NULL,
@@ -633,6 +638,64 @@ static bool njsSodaCollection_insertOneAndGetPostAsync(njsBaton *baton,
633638
}
634639

635640

641+
642+
//-----------------------------------------------------------------------------
643+
// njsSodaCollection_listIndexes()
644+
// Obtains a list of indexes from the collection and returns. Each index
645+
// is an object
646+
//-----------------------------------------------------------------------------
647+
NJS_NAPI_METHOD_IMPL_ASYNC(njsSodaCollection_listIndexes, 0, NULL)
648+
{
649+
return njsBaton_queueWork(baton, env, "listIndexes",
650+
njsSodaCollection_listIndexesAsync,
651+
njsSodaCollection_listIndexesPostAsync, returnValue);
652+
}
653+
654+
655+
//-----------------------------------------------------------------------------
656+
// njsSodaCollection_listIndexesAsync()
657+
// Worker function for njsSodaCollection_listIndexes().
658+
//-----------------------------------------------------------------------------
659+
static bool njsSodaCollection_listIndexesAsync(njsBaton *baton)
660+
{
661+
njsSodaCollection *coll = (njsSodaCollection*) baton->callingInstance;
662+
663+
baton->indexList = calloc(1, sizeof(dpiStringList));
664+
if (!baton->indexList)
665+
return njsBaton_setErrorInsufficientMemory(baton);
666+
if (dpiSodaColl_listIndexes(coll->handle, DPI_SODA_FLAGS_DEFAULT,
667+
baton->indexList) < 0) {
668+
return njsBaton_setErrorDPI(baton);
669+
}
670+
return true;
671+
}
672+
673+
674+
//-----------------------------------------------------------------------------
675+
// njsSodaCollection_listIndexesPostAsync()
676+
// Defines the value returned to JS
677+
//-----------------------------------------------------------------------------
678+
static bool njsSodaCollection_listIndexesPostAsync(njsBaton *baton,
679+
napi_env env, napi_value *result)
680+
{
681+
napi_value temp;
682+
uint32_t i;
683+
684+
NJS_CHECK_NAPI(env, napi_create_array_with_length(env,
685+
baton->indexList->numStrings, result))
686+
for (i = 0; i < baton->indexList->numStrings; i++) {
687+
NJS_CHECK_NAPI(env, napi_create_string_utf8(env,
688+
baton->indexList->strings[i],
689+
baton->indexList->stringLengths[i], &temp))
690+
NJS_CHECK_NAPI(env, napi_set_element(env, *result, i, temp))
691+
}
692+
693+
return true;
694+
}
695+
696+
697+
698+
636699
//-----------------------------------------------------------------------------
637700
// njsSodaCollection_newFromBaton()
638701
// Called when a SODA collection is being created from the baton.

test/list.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,6 +5502,14 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
55025502
285.3.3 msgId in enqOne/deqOne in reverse order
55035503
285.3.4 msgId in enqOne/deqOne in non-sequential order
55045504

5505+
286. listIndexes.js
5506+
286.1 listIndexes before creating any indexes
5507+
286.2 listIndexes after 1-createIndex
5508+
286.3 listIndexes after 2-createIndex
5509+
286.4 listIndexes after 2-createIndex 1-drop index
5510+
286.5 listIndexes after 2-createIndex 2-drop index
5511+
286.6 listIndexes after 3-createIndex
5512+
55055513
287. sodaOperationsLock.js
55065514
287.1 lock on sodaOperations
55075515

0 commit comments

Comments
 (0)