Skip to content

Commit 1352a73

Browse files
committed
feat: updated for Database APIs for open, close, and delete
1 parent 235ffe4 commit 1352a73

File tree

16 files changed

+742
-57
lines changed

16 files changed

+742
-57
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "src/cblite-js"]
22
path = src/cblite-js
33
url = [email protected]:Couchbase-Ecosystem/cblite-js.git
4+
[submodule "ios/cbl-js-swift"]
5+
path = ios/cbl-js-swift
6+
url = [email protected]:Couchbase-Ecosystem/cbl-js-swift.git
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { useContext, useLayoutEffect, useState } from 'react';
2+
import { View } from 'react-native';
3+
import { useNavigation } from '@react-navigation/native';
4+
import { useStyleScheme } from '@/components/Themed';
5+
import DatabaseNameForm from '@/components/DatabaseNameForm';
6+
import MaterialCommunityIcons from '@expo/vector-icons/build/MaterialCommunityIcons';
7+
import ResultListView from '@/components/ResultsListView';
8+
import close from '@/service/database/close';
9+
import DatabaseContext from '@/providers/DatabaseContext';
10+
11+
export default function DatabaseCloseScreen() {
12+
const { databases } = useContext(DatabaseContext)!;
13+
const [databaseName, setDatabaseName] = useState<string>('');
14+
const [resultMessage, setResultsMessage] = useState<string[]>([]);
15+
const navigation = useNavigation();
16+
const styles = useStyleScheme();
17+
useLayoutEffect(() => {
18+
navigation.setOptions({
19+
title: 'Database Open',
20+
headerBackTitle: 'Back',
21+
headerRight: () => (
22+
<MaterialCommunityIcons
23+
name="refresh"
24+
size={24}
25+
color="#428cff"
26+
onPress={reset}
27+
/>
28+
),
29+
});
30+
}, [navigation]);
31+
32+
function reset() {
33+
setDatabaseName('');
34+
setResultsMessage([]);
35+
}
36+
37+
const update = async () => {
38+
// validate that the database name isn't blank
39+
// and see if the database is in context, if so throw error
40+
// otherwise get a pointer to the database, open it, and add to the context
41+
if (databaseName === '') {
42+
setResultsMessage((prev) => [
43+
...prev,
44+
'Error: Database name is required',
45+
]);
46+
} else {
47+
try {
48+
const results = await close(databases, databaseName);
49+
setResultsMessage((prev) => [...prev, results]);
50+
} catch (error) {
51+
setResultsMessage((prev) => [...prev, '' + error]);
52+
}
53+
}
54+
};
55+
56+
return (
57+
<View style={styles.container}>
58+
<DatabaseNameForm
59+
setDatabaseName={setDatabaseName}
60+
databaseName={databaseName}
61+
/>
62+
<ResultListView messages={resultMessage} />
63+
</View>
64+
);
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { useContext, useLayoutEffect, useState } from 'react';
2+
import { View } from 'react-native';
3+
import { useNavigation } from '@react-navigation/native';
4+
import { useStyleScheme } from '@/components/Themed';
5+
import DatabaseNameForm from '@/components/DatabaseNameForm';
6+
import MaterialCommunityIcons from '@expo/vector-icons/build/MaterialCommunityIcons';
7+
import ResultListView from '@/components/ResultsListView';
8+
import deleteDatabase from '@/service/database/deleteDatabase';
9+
import DatabaseContext from '@/providers/DatabaseContext';
10+
11+
export default function DatabaseDeleteScreen() {
12+
const { databases, setDatabases } = useContext(DatabaseContext)!;
13+
const [databaseName, setDatabaseName] = useState<string>('');
14+
const [resultMessage, setResultsMessage] = useState<string[]>([]);
15+
const navigation = useNavigation();
16+
const styles = useStyleScheme();
17+
useLayoutEffect(() => {
18+
navigation.setOptions({
19+
title: 'Database Open',
20+
headerBackTitle: 'Back',
21+
headerRight: () => (
22+
<MaterialCommunityIcons
23+
name="refresh"
24+
size={24}
25+
color="#428cff"
26+
onPress={reset}
27+
/>
28+
),
29+
});
30+
}, [navigation]);
31+
32+
function reset() {
33+
setDatabaseName('');
34+
setResultsMessage([]);
35+
}
36+
37+
const update = async () => {
38+
// validate that the database name isn't blank
39+
// and see if the database is in context, if so throw error
40+
// otherwise get a pointer to the database, open it, and add to the context
41+
if (databaseName === '') {
42+
setResultsMessage((prev) => [
43+
...prev,
44+
'Error: Database name is required',
45+
]);
46+
} else {
47+
try {
48+
const results = await deleteDatabase(databases, databaseName);
49+
setResultsMessage((prev) => [...prev, results]);
50+
} catch (error) {
51+
setResultsMessage((prev) => [...prev, '' + error]);
52+
}
53+
}
54+
};
55+
56+
return (
57+
<View style={styles.container}>
58+
<DatabaseNameForm
59+
setDatabaseName={setDatabaseName}
60+
databaseName={databaseName}
61+
/>
62+
<ResultListView messages={resultMessage} />
63+
</View>
64+
);
65+
}

expo-example/app/database/open.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useLayoutEffect, useState } from 'react';
1+
import React, { useContext, useLayoutEffect, useState } from 'react';
22
import { View } from 'react-native';
33
import { useNavigation } from '@react-navigation/native';
44
import { useStyleScheme } from '@/components/Themed';
@@ -7,8 +7,11 @@ import MaterialCommunityIcons from '@expo/vector-icons/build/MaterialCommunityIc
77
import getFileDefaultPath from '@/service/file/getFileDefaultPath';
88
import DatabaseConfigForm from '@/components/DatabaseConfigForm';
99
import ResultListView from '@/components/ResultsListView';
10+
import open from '@/service/database/open';
11+
import DatabaseContext from '@/providers/DatabaseContext';
1012

1113
export default function DatabaseOpenScreen() {
14+
const { databases, setDatabases } = useContext(DatabaseContext)!;
1215
const [databaseName, setDatabaseName] = useState<string>('');
1316
const [fileLocation, setFileLocation] = useState<string>('');
1417
const [encryptionKey, setEncryptionKey] = useState<string>('');
@@ -38,13 +41,27 @@ export default function DatabaseOpenScreen() {
3841
}
3942

4043
const update = async () => {
41-
if (databaseName !== '') {
42-
} else {
44+
// validate that the database name isn't blank
45+
// and see if the database is in context, if so throw error
46+
// otherwise get a pointer to the database, open it, and add to the context
47+
if (databaseName === '') {
4348
setResultsMessage((prev) => [
4449
...prev,
4550
'Error: Database name is required',
4651
]);
47-
return;
52+
} else {
53+
try {
54+
const results = await open(
55+
databases,
56+
setDatabases,
57+
databaseName,
58+
fileLocation,
59+
encryptionKey
60+
);
61+
setResultsMessage((prev) => [...prev, results]);
62+
} catch (error) {
63+
setResultsMessage((prev) => [...prev, '' + error]);
64+
}
4865
}
4966
};
5067

expo-example/components/DatabaseConfigForm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export default function DatabaseConfigForm({
4141
placeholderTextColor={placeholderTextColor}
4242
onChangeText={(newText) => setFileLocation(newText)}
4343
defaultValue={fileLocation}
44+
multiline={true}
45+
numberOfLines={4}
4446
/>
4547
<TextInput
4648
style={[styles.textInput, { color: textColor }]}

expo-example/components/DatabaseNameForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function DatabaseNameForm({
1818
<>
1919
<DatabaseHeaderView />
2020
<TextInput
21+
autoCapitalize="none"
2122
style={[styles.textInput, { color: textColor }]}
2223
placeholder="Database Name"
2324
placeholderTextColor={placeholderTextColor}

expo-example/ios/expoexample.xcodeproj/project.pbxproj

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
1111
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1212
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
13-
1CBC052D29FC7AECA7384F91 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4D30347EB60E348D8B0D4FDC /* PrivacyInfo.xcprivacy */; };
1413
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */; };
15-
77353C10CB6E44EBA26C45C4 /* noop-file.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C1BC9A5E4EF4B5C894C7E7F /* noop-file.swift */; };
1614
96905EF65AED1B983A6B3ABC /* libPods-expoexample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 58EEBF8E8E6FB1BC6CAF49B5 /* libPods-expoexample.a */; };
1715
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */; };
16+
B26F9497ECD4413AA32239A4 /* noop-file.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C6D6535F4384A76A2D92C52 /* noop-file.swift */; };
1817
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */ = {isa = PBXBuildFile; fileRef = BB2F792C24A3F905000567C9 /* Expo.plist */; };
18+
BD22CB67F85B53A603A58CCF /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = ADEDEA080E7648660C596D00 /* PrivacyInfo.xcprivacy */; };
1919
/* End PBXBuildFile section */
2020

2121
/* Begin PBXFileReference section */
22+
115578E985A2425AB96E801E /* expoexample-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.c.h; name = "expoexample-Bridging-Header.h"; path = "expoexample/expoexample-Bridging-Header.h"; sourceTree = "<group>"; };
2223
13B07F961A680F5B00A75B9A /* expoexample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = expoexample.app; sourceTree = BUILT_PRODUCTS_DIR; };
2324
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = expoexample/AppDelegate.h; sourceTree = "<group>"; };
2425
13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = expoexample/AppDelegate.mm; sourceTree = "<group>"; };
2526
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = expoexample/Images.xcassets; sourceTree = "<group>"; };
2627
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = expoexample/Info.plist; sourceTree = "<group>"; };
2728
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = expoexample/main.m; sourceTree = "<group>"; };
28-
4C1BC9A5E4EF4B5C894C7E7F /* noop-file.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "noop-file.swift"; path = "expoexample/noop-file.swift"; sourceTree = "<group>"; };
29-
4D30347EB60E348D8B0D4FDC /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = expoexample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3029
58EEBF8E8E6FB1BC6CAF49B5 /* libPods-expoexample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-expoexample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3130
6C2E3173556A471DD304B334 /* Pods-expoexample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-expoexample.debug.xcconfig"; path = "Target Support Files/Pods-expoexample/Pods-expoexample.debug.xcconfig"; sourceTree = "<group>"; };
3231
7A4D352CD337FB3A3BF06240 /* Pods-expoexample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-expoexample.release.xcconfig"; path = "Target Support Files/Pods-expoexample/Pods-expoexample.release.xcconfig"; sourceTree = "<group>"; };
33-
A8162872A87E451EA856E28B /* expoexample-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.c.h; name = "expoexample-Bridging-Header.h"; path = "expoexample/expoexample-Bridging-Header.h"; sourceTree = "<group>"; };
32+
9C6D6535F4384A76A2D92C52 /* noop-file.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "noop-file.swift"; path = "expoexample/noop-file.swift"; sourceTree = "<group>"; };
3433
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = expoexample/SplashScreen.storyboard; sourceTree = "<group>"; };
34+
ADEDEA080E7648660C596D00 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = expoexample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3535
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
3636
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
3737
FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ExpoModulesProvider.swift; path = "Pods/Target Support Files/Pods-expoexample/ExpoModulesProvider.swift"; sourceTree = "<group>"; };
@@ -59,9 +59,9 @@
5959
13B07FB61A68108700A75B9A /* Info.plist */,
6060
13B07FB71A68108700A75B9A /* main.m */,
6161
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */,
62-
4C1BC9A5E4EF4B5C894C7E7F /* noop-file.swift */,
63-
A8162872A87E451EA856E28B /* expoexample-Bridging-Header.h */,
64-
4D30347EB60E348D8B0D4FDC /* PrivacyInfo.xcprivacy */,
62+
9C6D6535F4384A76A2D92C52 /* noop-file.swift */,
63+
115578E985A2425AB96E801E /* expoexample-Bridging-Header.h */,
64+
ADEDEA080E7648660C596D00 /* PrivacyInfo.xcprivacy */,
6565
);
6666
name = expoexample;
6767
sourceTree = "<group>";
@@ -147,13 +147,13 @@
147147
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "expoexample" */;
148148
buildPhases = (
149149
08A4A3CD28434E44B6B9DE2E /* [CP] Check Pods Manifest.lock */,
150-
D963BD1CCDCF5891E708D554 /* [Expo] Configure project */,
150+
C31B03312DD887F0BEE04EE0 /* [Expo] Configure project */,
151151
13B07F871A680F5B00A75B9A /* Sources */,
152152
13B07F8C1A680F5B00A75B9A /* Frameworks */,
153153
13B07F8E1A680F5B00A75B9A /* Resources */,
154154
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
155155
800E24972A6A228C8D4807E9 /* [CP] Copy Pods Resources */,
156-
CD91953A4D6271A131E6C36F /* [CP] Embed Pods Frameworks */,
156+
CC91A023482B9AC2C8B96CF4 /* [CP] Embed Pods Frameworks */,
157157
);
158158
buildRules = (
159159
);
@@ -203,7 +203,7 @@
203203
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */,
204204
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
205205
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */,
206-
1CBC052D29FC7AECA7384F91 /* PrivacyInfo.xcprivacy in Resources */,
206+
BD22CB67F85B53A603A58CCF /* PrivacyInfo.xcprivacy in Resources */,
207207
);
208208
runOnlyForDeploymentPostprocessing = 0;
209209
};
@@ -277,44 +277,44 @@
277277
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-expoexample/Pods-expoexample-resources.sh\"\n";
278278
showEnvVarsInLog = 0;
279279
};
280-
CD91953A4D6271A131E6C36F /* [CP] Embed Pods Frameworks */ = {
280+
C31B03312DD887F0BEE04EE0 /* [Expo] Configure project */ = {
281281
isa = PBXShellScriptBuildPhase;
282+
alwaysOutOfDate = 1;
282283
buildActionMask = 2147483647;
283284
files = (
284285
);
286+
inputFileListPaths = (
287+
);
285288
inputPaths = (
286-
"${PODS_ROOT}/Target Support Files/Pods-expoexample/Pods-expoexample-frameworks.sh",
287-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/CouchbaseLite-Swift-Enterprise/CouchbaseLiteSwift.framework/CouchbaseLiteSwift",
288-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes",
289289
);
290-
name = "[CP] Embed Pods Frameworks";
290+
name = "[Expo] Configure project";
291+
outputFileListPaths = (
292+
);
291293
outputPaths = (
292-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CouchbaseLiteSwift.framework",
293-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework",
294294
);
295295
runOnlyForDeploymentPostprocessing = 0;
296296
shellPath = /bin/sh;
297-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-expoexample/Pods-expoexample-frameworks.sh\"\n";
298-
showEnvVarsInLog = 0;
297+
shellScript = "# This script configures Expo modules and generates the modules provider file.\nbash -l -c \"./Pods/Target\\ Support\\ Files/Pods-expoexample/expo-configure-project.sh\"\n";
299298
};
300-
D963BD1CCDCF5891E708D554 /* [Expo] Configure project */ = {
299+
CC91A023482B9AC2C8B96CF4 /* [CP] Embed Pods Frameworks */ = {
301300
isa = PBXShellScriptBuildPhase;
302-
alwaysOutOfDate = 1;
303301
buildActionMask = 2147483647;
304302
files = (
305303
);
306-
inputFileListPaths = (
307-
);
308304
inputPaths = (
305+
"${PODS_ROOT}/Target Support Files/Pods-expoexample/Pods-expoexample-frameworks.sh",
306+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/CouchbaseLite-Swift-Enterprise/CouchbaseLiteSwift.framework/CouchbaseLiteSwift",
307+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes",
309308
);
310-
name = "[Expo] Configure project";
311-
outputFileListPaths = (
312-
);
309+
name = "[CP] Embed Pods Frameworks";
313310
outputPaths = (
311+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CouchbaseLiteSwift.framework",
312+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework",
314313
);
315314
runOnlyForDeploymentPostprocessing = 0;
316315
shellPath = /bin/sh;
317-
shellScript = "# This script configures Expo modules and generates the modules provider file.\nbash -l -c \"./Pods/Target\\ Support\\ Files/Pods-expoexample/expo-configure-project.sh\"\n";
316+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-expoexample/Pods-expoexample-frameworks.sh\"\n";
317+
showEnvVarsInLog = 0;
318318
};
319319
/* End PBXShellScriptBuildPhase section */
320320

@@ -326,7 +326,7 @@
326326
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
327327
13B07FC11A68108700A75B9A /* main.m in Sources */,
328328
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */,
329-
77353C10CB6E44EBA26C45C4 /* noop-file.swift in Sources */,
329+
B26F9497ECD4413AA32239A4 /* noop-file.swift in Sources */,
330330
);
331331
runOnlyForDeploymentPostprocessing = 0;
332332
};

expo-example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"main": "expo-router/entry",
44
"version": "1.0.0",
55
"scripts": {
6+
"prebuild": "expo prebuild",
7+
"prebuild:clean": "expo prebuild --clean",
68
"start": "expo start",
79
"android": "expo run:android",
810
"ios": "expo run:ios",
9-
"web": "expo start --web",
1011
"test": "jest --watchAll"
1112
},
1213
"jest": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Database } from 'cbl-reactnative';
2+
3+
export default async function close(
4+
databases: Record<string, Database>,
5+
databaseName: string
6+
) {
7+
if (databaseName in databases) {
8+
throw new Error('Error: Database already in Context');
9+
} else {
10+
let database = databases[databaseName];
11+
await database.close();
12+
return 'Database closed successfully';
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Database } from 'cbl-reactnative';
2+
3+
export default async function deleteDatabase(
4+
databases: Record<string, Database>,
5+
databaseName: string
6+
) {
7+
if (databaseName in databases) {
8+
throw new Error('Error: Database already in Context');
9+
} else {
10+
let database = databases[databaseName];
11+
await database.deleteDatabase();
12+
return 'Database deleted successfully';
13+
}
14+
}

0 commit comments

Comments
 (0)