All Projects → an-rahulpandey → cordova-plugin-dbcopy

an-rahulpandey / cordova-plugin-dbcopy

Licence: Apache-2.0 license
Copy SQLite Database from www folder to default app database location

Programming Languages

objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cordova-plugin-dbcopy

cordova-plugin-example
Example Cordova plugin for iOS and Android to support blog post.
Stars: ✭ 15 (-83.33%)
Mutual labels:  cordova-android-plugin, cordova-plugin, phonegap-plugin, cordova-ios-plugin
cordova-plugin-downloadmanager
A Cordova plugin to download file in system's default download manager
Stars: ✭ 45 (-50%)
Mutual labels:  cordova, cordova-plugin, phonegap-plugin
cordova-swift3-plugin-example
Swift 3 Cordova plugin example to support blog post.
Stars: ✭ 23 (-74.44%)
Mutual labels:  cordova, cordova-plugin, phonegap-plugin
cordova-plugin-zeep
Zip compression/decompression for the cordova/phonegap platform
Stars: ✭ 27 (-70%)
Mutual labels:  cordova, cordova-android-plugin, cordova-plugin
Cordova Plugin Local Notifications
Cordova Local-Notification Plugin
Stars: ✭ 2,525 (+2705.56%)
Mutual labels:  cordova-android-plugin, cordova-plugin, cordova-ios-plugin
cordova-plugin-today-widget
Add a today widget app extension target to your cordova project.
Stars: ✭ 51 (-43.33%)
Mutual labels:  cordova, cordova-plugin, cordova-ios-plugin
cordova-plugin-flurryanalytics
Adds support for all that Flurry Analytics flavored goodness to your Cordova based apps
Stars: ✭ 23 (-74.44%)
Mutual labels:  cordova, cordova-plugin, phonegap-plugin
ionic-native-sms-retriever-plugin-master
Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
Stars: ✭ 16 (-82.22%)
Mutual labels:  cordova, cordova-plugin, phonegap-plugin
cordova-study
📱 Cordova学习记录,Cordova插件的使用,热更新、media、device、集成x5内核等等。
Stars: ✭ 19 (-78.89%)
Mutual labels:  cordova, cordova-plugin
cordova-line-login-plugin
A cordova plugin for easy implementation of LINE login using LineSDK.
Stars: ✭ 20 (-77.78%)
Mutual labels:  cordova, cordova-plugin
Create-a-custom-Cordova-plugin
How to create a custom cordova plugin and bridge it between your native code and a new or existing Cordova project
Stars: ✭ 32 (-64.44%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-purchases
Cordova in-app purchases and subscriptions made easy.
Stars: ✭ 52 (-42.22%)
Mutual labels:  cordova, cordova-plugin
hms-cordova-plugin
This repo contains all of Cordova HMS plugins.
Stars: ✭ 78 (-13.33%)
Mutual labels:  cordova, cordova-plugin
ionic-hockeyapp
Need HockeyApp in your Ionic application, add this package!
Stars: ✭ 19 (-78.89%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-webpack
Integrate webpack into your Cordova workflow.
Stars: ✭ 61 (-32.22%)
Mutual labels:  cordova, cordova-plugin
JiaCordova
在Cordova及插件的基础上封装一些常用的功能,不断更新中
Stars: ✭ 35 (-61.11%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-android-window-background
Simple Cordova plugin to set Android window background on start-up 🎨 🍭
Stars: ✭ 15 (-83.33%)
Mutual labels:  cordova, cordova-plugin
cordova-gmv-barcode-scanner
A Cordova barcode scanning plugin based on the Google Mobile Vision library for iOS & Android.
Stars: ✭ 48 (-46.67%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-wkkeyboardfix
Cordova plugin to provide a temporary fix for an iOS 12 and 13 bug involving keyboards in WKWebView.
Stars: ✭ 14 (-84.44%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-gctouch-id
Touch ID Plugin (Cordova) for iOS
Stars: ✭ 20 (-77.78%)
Mutual labels:  cordova-plugin, cordova-ios-plugin

cordova-plugin-dbcopy

Add a prepopulated SQLite database in your Phonegap/Cordova Android and iOS app.

IMPORTANT NOTE

  1. The database file may have extensions or not for e.g the db file name would be sample.db or sample.sqlite or sample. It doesn't matter what is the file extension, just remember to use the whole filename with extensions(if having one otherwise not) as a paramter when passing to the plugin methods.

  2. Location Parameters in plugin function means -

       location = 0; // (Disable iCloud Backup) If set will copy the database to Library/LocalDatabase. The database will not be synced by the iCloud Backup.
       or
       location = 1; // If set will copy the database to Library folder instead of Documents folder.
       or
       location = 2; // It will copy the database in the default SQLite Database directory. This is the default location for database
  1. For Android, please set the target-sdk-version to minimum 26 in config.xml

Database file location

The database file must be present inside the www folder.

Installation

Plugin can be install with simple cordova plugin add command -

cordova plugin add https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git

Plugin Response Success and Error

Plugin send the response in following format in case of any error or success -

{
  message : "message contains the response string like Invalid DB Location or DB Doesn't Exists or Db Copied Successfully",
  code: integer value such as 404, 200, 516
}

Code -

 404 - DB or Source or Destination Doesn't exists, see message string.
 516 - DB Already Exists.
 200 - Called Method Executed Successfully.

Methods

Currently there are five methods supported by the plugin.

Copy

This Method allows you the copy the database from www directory.

    window.plugins.sqlDB.copy(dbname, location, success,error);

Here -

dbname -> Is the name of the database you want to copy. The dbname can be filename (without extensions) or filename.db or filename.sqlite. The plugin will look for and copy the file according to the filename provided here. And the same file name should be used while opening the database via SQLitePlugin.

location -> You can pass three integer arguments here (Use 0 for Android)-

     (for ios only)
      location = 0; // (Disable iCloud Backup) If set will copy the database to Library/LocalDatabase. The database will not be synced by the iCloud Backup.
      or
      location = 1; // If set will copy the database to Library folder instead of Documents folder.
      or
      location = 2; // It will copy the database in the default SQLite Database directory. This is the default location for database

success -> function will be called if the db is copied sucessfully.

error -> function will be called if the there is some problem in copying the db or the file already exists on the location.

Check Database Available on External Storage

    window.plugins.sqlDB.checkDbOnStorage(dbname, source, success, error);

Here -

dbname -> Name of the database file which is available on external or intenral storage

source -> Full native path for the folder in which db file is present. The "/" must be added at the end of path. For.eg. /sdcard/mydb/

Copy Database from Device Storage

This is an untested version. Let me know if you have any suggestions. Also Pull Request are always welcome.

    window.plugins.sqlDB.copyDbFromStorage(dbname, location, source, deleteolddb, success, error);

Here -

dbname -> Is the name of the database you want to copy. The dbname can be filename (without extensions) or filename.db or filename.sqlite. The plugin will look for and copy the file according to the filename provided here. And the same file name should be used while opening the database via SQLitePlugin.

location -> You can pass three integer arguments here (Use 0 for Android)-

       (for ios only)
       location = 0; // (Disable iCloud Backup) If set will copy the database to Library/LocalDatabase. The database will not be synced by the iCloud Backup.
       or
       location = 1; // If set will copy the database to Library folder instead of Documents folder.
       or
       location = 2; // It will copy the database in the default SQLite Database directory. This is the default location for database

source -> Source File location like /sdcard/mydb/db.db. Please provide a valid existing location and the dbname should be present in the path.

deleteolddb -> A boolean value if set to true, will delete the existing db from the local app database folder before copying the new db. Please provide proper boolean value true or false;

success -> function will be called if the db is copied sucessfully.

error -> function will be called if the there is some problem in copying the db or the file already exists on the location.

Copy Database To Device Storage

This is an untested version. Let me know if you have any suggestions. Also Pull Request are always welcome.

    window.plugins.sqlDB.copyDbToStorage(dbname, location, destination, overwrite, success, error);

Here -

dbname -> Is the name of the database you want to copy. The dbname can be filename (without extensions) or filename.db or filename.sqlite. The plugin will look for and copy the file according to the filename provided here. And the same file name should be used while opening the database via SQLitePlugin.

location -> You can pass three integer arguments here (Use 0 for Android)-

   (for ios only)
   location = 0; // (Disable iCloud Backup) If set will copy the database to Library/LocalDatabase. The database will not be synced by the iCloud Backup.
   or
   location = 1; // If set will copy the database to Library folder instead of Documents folder.
   or
   location = 2; // It will copy the database in the default SQLite Database directory. This is the default location for database

destination -> Destination File location like /sdcard/mydb/ Please provide a valid existing location and "/" should be present at the end of the path. Do not append db name in the path.

overwrite -> if set to true, then will replace the file at the destination. Otherwise will throw an error, if destination file already exists.

success -> function will be called if the db is copied sucessfully.

error -> function will be called if the there is some problem in copying the db or the file already exists on the location.

Remove

This method allows you to remove the database from the apps default database storage location.

    window.plugins.sqlDB.remove(dbname, location, success,error);

Here -

dbname -> Is the name of the database you want to remove. If the database file is having any extension, please provide that also.

location -> The integer value for the location of database, see the copy method for options.

success -> function will be called if the db is removed sucessfully.

error -> function will be called if the there is some problem in removing the db or the file doesn't exists on the default database storage location.

###Example Usage

In your JavaScript or HTML use the following method -

function dbcopy()
{
        //Database filename to be copied is demo.db

        //location = 0, will copy the db to default SQLite Database Directory, /Library/LocalDatabase (Disable iCloud Backup)
        window.plugins.sqlDB.copy("demo.db", 0, copysuccess,copyerror);

        or

        //location = 1, will copy the database to /Library folder
        window.plugins.sqlDB.copy("demo.db", 1, copysuccess,copyerror);

        or

        //location = 2, will copy the database to /Documents folder 
        window.plugins.sqlDB.copy("demo.db", 2, copysuccess,copyerror);

}

function removeDB()
{
      var location = 1;
      window.plugins.sqlDB.remove("demo.db", location, rmsuccess,rmerror);  
}

function copysuccess()
{
        //open db and run your queries
         db = window.sqlitePlugin.openDatabase({name: "demo.db"});.
}

function copyerror(e)
{
        //db already exists or problem in copying the db file. Check the Log.
        console.log("Error Code = "+JSON.stringify(e));
        //e.code = 516 => if db exists
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].