Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions android/src/main/java/com/op/sqlite/OPSQLiteModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import java.io.InputStream
import java.io.OutputStream
import com.facebook.react.util.RNLog;

//@ReactModule(name = OPSQLiteModule.NAME)
internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) {
override fun getName(): String {
return NAME
}

fun getTypedExportedConstants(): MutableMap<String, Any> {
val constants: MutableMap<String, Any> = HashMap()
fun getTypedExportedConstants(): MutableMap<String, Any?> {
val constants: MutableMap<String, Any?> = HashMap()
val context = reactApplicationContext
val dbPath =
context.getDatabasePath("defaultDatabase")
Expand All @@ -28,14 +27,14 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextB
constants["ANDROID_DATABASE_PATH"] = dbPath
val filesPath = context.filesDir.absolutePath
constants["ANDROID_FILES_PATH"] = filesPath
val externalFilesDir = context.getExternalFilesDir(null)!!.absolutePath
constants["ANDROID_EXTERNAL_FILES_PATH"] = externalFilesDir
constants["IOS_DOCUMENT_PATH"] = ""
constants["IOS_LIBRARY_PATH"] = ""
val externalFilesDir = context.getExternalFilesDir(null)
constants["ANDROID_EXTERNAL_FILES_PATH"] = externalFilesDir?.absolutePath
constants["IOS_DOCUMENT_PATH"] = null
constants["IOS_LIBRARY_PATH"] = null
return constants
}

override fun getConstants(): MutableMap<String, Any>? {
override fun getConstants(): MutableMap<String, Any?> {
return getTypedExportedConstants()
}

Expand All @@ -53,7 +52,6 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextB
@ReactMethod(isBlockingSynchronousMethod = true)
fun getDylibPath(bundleId: String, name: String): Boolean {
throw Exception("Do not call getDylibPath on Android")
return true
}

@ReactMethod
Expand Down
8 changes: 5 additions & 3 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ const db = open({
});
```

If you want to access the SD card app's directory:
If you want to access the SD card app's directory. However, `ANDROID_EXTERNAL_FILES_PATH` **can be null**, sometimes there are OS/Device level errors on which the OS does not detect the directory correctly. You should always have a fallback.

```tsx
const db = open({
name: 'myDB',
location:
Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_EXTERNAL_FILES_PATH,
Platform.OS === 'ios'
? IOS_LIBRARY_PATH
: ANDROID_EXTERNAL_FILES_PATH ?? ANDROID_DATABASE_PATH,
});
```

Expand All @@ -63,7 +65,7 @@ const db = open({
location:
Platform.OS === 'ios'
? IOS_LIBRARY_PATH
: `${ANDROID_EXTERNAL_FILES_PATH}/dbs/`,
: `${ANDROID_EXTERNAL_FILES_PATH}/databases/`,
});
```

Expand Down
Loading