Registry / database / cordova-plugin-dbcopy

cordova-plugin-dbcopy

JSON →
library2.1.2jsnpmunverified

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-dbcopy
INSTALL
IMPORT
SIG · CORDOVA-PLUGIN-DBC
C
cordova-plugin-dbcopy
databasejavascriptv2.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

window.plugins.sqlDB
document.addEventListener('deviceready', function() { console.log(window.plugins.sqlDB); });
import { sqlDB } from 'cordova-plugin-dbcopy';
Cordova plugins expose their APIs globally on the `window.plugins` object after the `deviceready` event fires. Direct ES module or CommonJS imports are not applicable.
window.plugins.sqlDB.copy
window.plugins.sqlDB.copy(dbname, location, successCallback, errorCallback);
const copy = require('cordova-plugin-dbcopy').copy;
Access the `copy` method directly from the globally available `window.plugins.sqlDB` object. Ensure `deviceready` has fired.
window.plugins.sqlDB.checkDbOnStorage
window.plugins.sqlDB.checkDbOnStorage(dbname, sourcePath, successCallback, errorCallback);
checkDbOnStorage(dbname, sourcePath, successCallback, errorCallback);
Like other plugin methods, `checkDbOnStorage` must be called on the `window.plugins.sqlDB` object. It is not globally available by itself.

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.

document.addEventListener('deviceready', function() { const dbName = 'myprepopulated.db'; // For iOS, location 0 disables iCloud backup. For Android, use 0. const location = 0; window.plugins.sqlDB.copy(dbName, location, function(response) { console.log('Database copy success:', response.message, 'Code:', response.code); // Now you can open the database using SQLitePlugin // const db = window.sqlitePlugin.openDatabase({ // name: dbName, // location: 'default' // Or other appropriate location based on 'location' param above // }); // db.transaction(function(tx) { /* ... */ }); }, function(error) { console.error('Database copy error:', error.message, 'Code:', error.code); }); }, false);
Debug
Known issues
gotchaFor Android, the `target-sdk-version` in `config.xml` must be set to a minimum of 26 to ensure proper plugin functionality, particularly regarding file access permissions.
fix
Add `<preference name="android-targetSdkVersion" value="26" />` to your `config.xml` file.
affects: >=2.0.0
gotchaThe `location` parameter for the `copy` method has different meanings and recommendations for iOS and Android. For Android, always use `0`. For iOS, `0` disables iCloud Backup, `1` copies to `Library` (synced by iCloud), and `2` copies to the default SQLite Database directory.
fix
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);`
affects: >=1.0.0
gotchaWhen specifying the database filename, include the full name with any extensions (e.g., `sample.db` or `sample.sqlite`). The plugin will use the exact string provided.
fix
Pass the complete filename string including its extension, if any, to the `dbname` parameter. For example, `window.plugins.sqlDB.copy('mydata.sqlite', ...);`
affects: >=1.0.0
deprecatedThe `copyDbFromStorage` method is marked as 'untested' in the README and its reliability may be questionable. Use with caution or consider contributing to its testing and improvement.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
message contains the response string like Invalid DB Location or DB Doesn't Exists or Db Copied Successfully, code: 404
The specified database file (`dbname`) was not found in the `www` directory, or the source/destination path for external storage operations is invalid.
fix
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.
message contains the response string like Db Already Exists, code: 516
A database with the specified name already exists at the target location and the plugin is configured not to overwrite it.
fix
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.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
10
OpenAI (training)
2
Resources
cordova-plugin-dbcopy — npm install cordova-plugin-dbcopy · libregistry