Control where DuckDB database files are stored on iOS and Android.
When you open a database with a relative path, it resolves against the app's default documents directory:
import { HybridDuckDB } from 'react-native-duckdb'
// Relative path — stored in the default documents directory
const db = HybridDuckDB.open('myapp.duckdb', {})The default directory is NSDocumentDirectory on iOS and getFilesDir() on Android.
Five readonly properties expose platform-specific storage directories:
| Property | iOS | Android | Backed Up |
|---|---|---|---|
documentsPath |
NSDocumentDirectory |
getFilesDir() |
iCloud ✅ / Auto Backup ✅ |
libraryPath |
NSLibraryDirectory |
getFilesDir() |
No ❌ / Auto Backup ✅ |
databasePath |
NSDocumentDirectory |
getDatabasePath() parent |
iCloud ✅ / Auto Backup ✅ |
externalStoragePath |
"" (N/A) |
getExternalFilesDir(null) |
No ❌ |
defaultPath |
Same as documentsPath |
Same as documentsPath |
— |
Access them directly on the HybridDuckDB object:
console.log(HybridDuckDB.documentsPath) // /var/mobile/.../Documents
console.log(HybridDuckDB.libraryPath) // /var/mobile/.../LibraryFor convenience, named constants are also exported from the package root:
import {
DOCUMENTS_PATH,
LIBRARY_PATH,
DATABASE_PATH,
EXTERNAL_STORAGE_PATH,
DEFAULT_PATH,
} from 'react-native-duckdb'These are evaluated at module load time and hold the same values as the HybridDuckDB properties.
// Stored in documentsPath — simplest option
const db = HybridDuckDB.open('analytics.duckdb', {})import { HybridDuckDB } from 'react-native-duckdb'
const path = `${HybridDuckDB.libraryPath}/analytics.duckdb`
const db = HybridDuckDB.open(path, {})Use libraryPath for large databases that can be regenerated — avoids consuming the user's iCloud storage quota.
import { HybridDuckDB } from 'react-native-duckdb'
const dir = HybridDuckDB.externalStoragePath || HybridDuckDB.documentsPath
const db = HybridDuckDB.open(`${dir}/large_dataset.duckdb`, {})externalStoragePath returns an empty string on iOS and when external storage is unavailable on Android.
const db = HybridDuckDB.open(':memory:', {})
// No file is created on diskBy default, files in NSDocumentDirectory (documentsPath) are included in iCloud backups. For large databases that can be regenerated, consider:
-
Use
libraryPath—NSLibraryDirectoryis excluded from iCloud backup by default. This is the recommended approach for most apps. -
Per-file exclusion — If you must store in Documents, you can exclude individual files from backup using
NSURLIsExcludedFromBackupKey. This requires native code and is outside the scope of this library.
Recommendation: Use
libraryPathfor databases that hold cached or regenerable data. UsedocumentsPathonly for user-created content that should survive device restore.
On Android, files in getFilesDir() (documentsPath / libraryPath) are included in Auto Backup by default. To exclude specific paths:
-
Set
android:allowBackup="false"in yourAndroidManifest.xmlto disable all auto-backup. -
Or create a
backup_rules.xmlto selectively exclude paths:
<!-- res/xml/backup_rules.xml -->
<full-backup-content>
<exclude domain="file" path="large_cache.duckdb" />
</full-backup-content>Then reference it in your manifest:
<application android:fullBackupContent="@xml/backup_rules" ...>Files in getExternalFilesDir() (externalStoragePath) are not included in auto-backup.
All path values are resolved at app startup (during native module initialization) and remain constant for the app's lifetime. They are safe to read synchronously at any point after the module loads.