Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript solution for pre-populated databases #683

Open
brodycj opened this issue May 9, 2017 · 0 comments
Open

JavaScript solution for pre-populated databases #683

brodycj opened this issue May 9, 2017 · 0 comments

Comments

@brodycj
Copy link
Contributor

brodycj commented May 9, 2017

From storesafe/cordova-sqlite-storage-help#26 I identified 7 pre-populated database alternatives:

  • 1: Use cordova-sqlite-ext with createFromLocation option in sqlitePlugin.openDatabase
  • 2: Use cordova-sqlite-storage (or any other version) with a plugin such as cordova-plugin-dbcopy (not supported here)
  • 3: Use File API to copy database from another location (such as www) from JavaScript into the proper location then use cordova-sqlite-storage (or any other version) to open the database
  • 4: Download the sqlite database file using something like FileTransfer, store it in the proper location, and the use cordova-sqlite-storage (or any other version)
  • 5: Fetch the data by REST using AJAX, possibly using a library call such as $.ajax and store it (using cordova-sqlite-storage or any other version)
  • 6: INSERT the data records from another source such as a sqlite dump or a hard coded object in JavaScript
  • 7: use https://github.com/dpa99c/cordova-sqlite-porter to import from dump, JSON, etc.

At this point the createFromLocation option discussed in option 1 will only work in cordova-sqlite-ext (and certain other cordova-sqlite-evplus-legacy versions). (The other options will work in all sqlite plugin versions.) The rest of this discussion concerns a solution for option 1.

Ideally it should be possible to have a JavaScript solution for option 1 that works together with cordova-plugin-file and this plugin. My idea is that the JavaScript solution should be able to determine the correct destination path from the default database directory path (#680) and then copy the pre-populated database into the right place. An alternative of course would be to copy the database into an arbitrary path and then open the database from there ref: #681.

The tricky part is how to read from the www resource location ref:

A solution for Android could be to use an XHR file reader such as https://github.com/macdonst/XhrFileReader ref:

Unfortunately this does not seem so good for potentially large binary files.

I can think of the following solutions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant