Skip to content

Commit cd938e6

Browse files
committed
feat: added support for index creation - not tested yet
1 parent 9d91c40 commit cd938e6

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-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"
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"

expo-example/app/collection/indexing/create.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CBLCollectionActionContainer from '@/components/CBLCollectionActionContai
44
import HeaderView from '@/components/HeaderView';
55
import { Divider } from '@gluestack-ui/themed';
66
import { StyledTextInput } from '@/components/StyledTextInput';
7+
import create from '@/service/indexes/create';
78

89
export default function IndexCreateScreen() {
910
const [indexName, setIndexName] = useState<string>('');
@@ -15,9 +16,13 @@ export default function IndexCreateScreen() {
1516
}
1617

1718
async function update(collection: Collection): Promise<string[]> {
18-
return [
19-
`Collection: <${collection.fullName()}> was retrieved from database <${collection.database.getName()}>`,
20-
];
19+
try {
20+
await create(collection, indexName, indexProperties);
21+
return [`Index ${indexName} was created successfully`];
22+
} catch (error) {
23+
// @ts-ignore
24+
return [error.message];
25+
}
2126
}
2227

2328
return (

expo-example/ios/expoexample/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5555
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5656
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
57+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
58+
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
5759
</array>
5860
<key>UILaunchStoryboardName</key>
5961
<string>SplashScreen</string>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Collection, ValueIndexItem, IndexBuilder } from 'cbl-reactnative';
2+
3+
export default async function create(
4+
collection: Collection,
5+
indexName: string,
6+
indexProperties: string
7+
): Promise<void> {
8+
const rawIndexes = indexProperties
9+
.split(',')
10+
.map((property) => property.trim());
11+
if (rawIndexes.length > 0 && indexName.length > 0) {
12+
//create value index items to be added to the index using
13+
//IndexBuilder
14+
let valueIndexes: ValueIndexItem[] = [];
15+
for (let i = 0; i < rawIndexes.length; i++) {
16+
valueIndexes.push(ValueIndexItem.property(rawIndexes[i].trim()));
17+
}
18+
const index = IndexBuilder.valueIndex(...valueIndexes);
19+
20+
await collection.createIndex(indexName, index);
21+
} else {
22+
throw new Error('Index name and properties are required');
23+
}
24+
}

src/cblite-js

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ camelcase@^7.0.1:
26752675
caniuse-lite@^1.0.30001640:
26762676
version "1.0.30001640"
26772677

2678-
"cbl-reactnative-example@file:/Users/labeaaa/Developer/couchbase/cbl-reactnative/example":
2678+
"cbl-reactnative-example@file:/Users/aaron.labeau/Developer/Couchbase/cbl-reactnative/example":
26792679
version "0.0.1"
26802680
resolved "file:example"
26812681
dependencies:

0 commit comments

Comments
 (0)