cordova-plugin-dbcopy is a Cordova/Phonegap plugin designed to copy a pre-populated SQLite database from the `www` directory of an application to the device's native app database directory. The current stable version is 2.1.2. This plugin addresses a common need for mobile applications that require initial data or a pre-configured database upon first launch, providing methods to copy the database, check its existence, and handle different storage locations, especially for iOS iCloud backup exclusion. Its release cadence appears to be stable rather than rapid, focusing on core functionality within the Cordova ecosystem. A key differentiator is its explicit handling of platform-specific database locations and error responses for common issues like file not found or already existing databases.
npm install cordova-plugin-dbcopyVerified import paths — ran on the pinned version, not inferred.
This code snippet demonstrates how to copy a pre-populated database from the `www` directory to the app's data directory after the Cordova `deviceready` event. It includes basic error handling.
Add `<preference name="android-targetSdkVersion" value="26" />` to your `config.xml` file.
Ensure `location = 0` for Android. For iOS, choose `0`, `1`, or `2` based on iCloud backup requirements. For example, `window.plugins.sqlDB.copy(dbname, 0, success, error);`
Pass the complete filename string including its extension, if any, to the `dbname` parameter. For example, `window.plugins.sqlDB.copy('mydata.sqlite', ...);`If `copyDbFromStorage` is critical for your use case, test thoroughly across target platforms and consider reviewing or contributing to the plugin's source code. Otherwise, prioritize the `copy` method.
Verify that your database file (e.g., `mydata.db`) is correctly placed inside the `www` folder of your Cordova project. Ensure the filename passed to `copy` is exact (including extension if present). For `checkDbOnStorage` or `copyDbFromStorage`, confirm the `source` path is a valid native file system path.
This is often expected behavior. If you need to overwrite, you might need to manually delete the existing database first using a file system plugin (e.g., `cordova-plugin-file`) or handle the error gracefully if overwriting is not desired. The `copy` method itself doesn't offer an overwrite option directly; subsequent calls will fail if the DB exists.
No dependency data recorded yet.