Skip to content

Commit 3d0aa4d

Browse files
committed
feat: added index create and index list code that's testing and works
1 parent cd938e6 commit 3d0aa4d

File tree

6 files changed

+79
-7
lines changed

6 files changed

+79
-7
lines changed

expo-example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ allprojects {
3939
maven { url 'https://www.jitpack.io' }
4040
}
4141
}
42-
apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"
42+
apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"apply from: "../../android/build.gradle"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { Collection } from 'cbl-reactnative';
3+
import CBLCollectionActionContainer from '@/components/CBLCollectionActionContainer';
4+
import listIndexes from '@/service/indexes/list';
5+
6+
export default function IndexesListScreen() {
7+
function reset() {}
8+
9+
async function update(collection: Collection): Promise<string[]> {
10+
try {
11+
const indexes = await listIndexes(collection);
12+
if (indexes.length > 0) {
13+
return indexes;
14+
} else {
15+
return ['No indexes found.'];
16+
}
17+
} catch (error) {
18+
// @ts-ignore
19+
return [error.message];
20+
}
21+
}
22+
23+
return (
24+
<CBLCollectionActionContainer
25+
handleUpdatePressed={update}
26+
handleResetPressed={reset}
27+
screenTitle="List Indexes"
28+
/>
29+
);
30+
}

expo-example/ios/expoexample/Info.plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5757
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5858
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
59+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
60+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
61+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
62+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
63+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
64+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5965
</array>
6066
<key>UILaunchStoryboardName</key>
6167
<string>SplashScreen</string>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Collection } from 'cbl-reactnative';
2+
3+
export default async function listIndexes(
4+
collection: Collection
5+
): Promise<string[]> {
6+
return await collection.indexes();
7+
}

ios/DataAdapter.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,13 @@ public class DataAdapter {
176176
public func adaptIndexToArrayAny(dict: NSDictionary, reject: @escaping RCTPromiseRejectBlock) -> (Bool, IndexArgs){
177177
let indexArgs = IndexArgs()
178178
var isError = false
179-
var result = [[Any]]()
180179
indexArgs.indexType = String(dict["type"] as! NSString)
181-
for (key, value) in dict["items"] as! NSDictionary {
182-
result.append([key, value])
180+
let items = dict["items"] as! NSArray
181+
for item in items {
182+
if let array = item as? [Any] {
183+
indexArgs.indexes.append(array)
184+
}
183185
}
184-
indexArgs.indexes = result
185186
if (indexArgs.indexes.isEmpty || indexArgs.indexType.isEmpty){
186187
isError = true
187188
reject("INDEX_ERROR", "Can't parse Index information", nil)

src/CblReactNativeEngine.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,22 @@ export class CblReactNativeEngine implements ICoreEngine {
109109
}
110110

111111
collection_CreateIndex(args: CollectionCreateIndexArgs): Promise<void> {
112-
return Promise.resolve(undefined);
112+
return new Promise((resolve, reject) => {
113+
this.CblReactNative.collection_CreateIndex(
114+
args.indexName,
115+
args.index,
116+
args.collectionName,
117+
args.scopeName,
118+
args.name
119+
).then(
120+
() => {
121+
resolve();
122+
},
123+
(error: any) => {
124+
reject(error);
125+
}
126+
);
127+
});
113128
}
114129

115130
collection_DeleteCollection(args: CollectionArgs): Promise<void> {
@@ -282,7 +297,20 @@ export class CblReactNativeEngine implements ICoreEngine {
282297
}
283298

284299
collection_GetIndexes(args: CollectionArgs): Promise<{ indexes: string[] }> {
285-
return Promise.resolve({ indexes: [] });
300+
return new Promise((resolve, reject) => {
301+
this.CblReactNative.collection_GetIndexes(
302+
args.name,
303+
args.scopeName,
304+
args.collectionName
305+
).then(
306+
(items: { indexes: string[] }) => {
307+
resolve(items);
308+
},
309+
(error: any) => {
310+
reject(error);
311+
}
312+
);
313+
});
286314
}
287315

288316
collection_PurgeDocument(args: CollectionPurgeDocumentArgs): Promise<void> {

0 commit comments

Comments
 (0)