brodycj / ask-me-anything

ASK ME ANYTHING such as support, ideas, or personal questions
Creative Commons Attribution 4.0 International
4 stars 1 forks source link

Starting new SQLite plugin design for Apache Cordova #3

Open brodycj opened 4 years ago

brodycj commented 4 years ago

Background: Apache Cordova enables people to develop mobile apps for Android, iOS, and other platforms in HTML and JavaScript. I have been maintaining a widely used plugin that provides SQLite storage capability with a JavaScript API. The plugin has a somewhat complex JavaScript API that closely emulates the draft and deprecated Web SQL API.

I am now starting a new SQLite plugin design based on a lightweight SQLite connection management component, with a preview already available in: brodybits/sqlite-batch-connection-support-preview-2020-01

Note that the preview is archived since I am not interested in handling any PRs at this time. Any questions, ideas, or suggestions should be raised here or in a new issue on this project.

The preview was designed to be thread-safe, with exception for a single initialization function that should be run from the main thread. It includes a proof-of-concept demo of a new Cordova plugin that provides many of the batch SQL capabilities like the draft Web SQL API.

Here are the major goals that I would like to achieve, in response to my past experience and some recent user demand:

Major non-goals:

I think that the preview with the Cordova plugin demo already fulfills all goals except for running SQL operations in background threads. Access from custom Java code on Android is demonstrated in sample code in the documentation of the preview.

Note that the API of the preview should be considered a draft API and is subject to change when I publish the new plugin.

I am raising this issue as the new step in continuation from a discussion on the existing plugin: https://github.com/xpbrew/cordova-sqlite-storage/issues/862

I will probably need a few more weeks to get something ready to replace the existing plugin and am giving priority to paying customers. Please contact chris@brody.consulting if interested.

clearfram3 commented 4 years ago

Do you have any plans to move to Capacitor?

brodycj commented 4 years ago

My apologies for the delay. Apache Cordova is my primary target; Capacitor should be able to run almost any plugin working on Cordova. A major advantage of Cordova is no need for platform artifacts to be committed in the git history.

gatelli commented 4 years ago

Hi, do you have an approximated release date for that ? May I start to use this SQLite plugin expecting the next one will be compatible ? Thanks!

brodycj commented 4 years ago

I am working on something for both Cordova & React Native, should be ready in the next 1-2 weeks or so.

T3chTobi commented 4 years ago

@brodybits are there any news about the new sql plugin for Cordova?

brodycj commented 4 years ago

My apologies for the delays. I may need another 1-2 weeks or so.

steveetm commented 4 years ago

Hey, any update on this?:)

brodycj commented 4 years ago

New, unstable plugin version is here: https://github.com/brodybits/cordova-plugin-sqlite-batch-connection-manager-core-unstable-0x

The native SQLite3 libraries are not committed in master. TODO item is to update the plugin to install native SQLite3 libraries using pod for iOS, Maven for Android. Until then, it is recommended to install from an unstable build release tag, for example:

cordova plugin add github: com/brodybits/cordova-plugin-sqlite-batch-connection-manager-core-unstable-0x#build-2020-06-17-01

The database file path generally needs to be resolved using cordova-sqlite-storage-file; database path is still in unstable path on iOS.

steveetm commented 4 years ago

Thanks for the response! I couldn't yet check it deeply but are there any plans to move from old websql limitations like persist an sqlite transaction more than a tick, essentially making async/await possible in transactions?

brodycj commented 4 years ago

The new plugin API is pretty low-level, and I would generally recommend some kind of a JavaScript wrapper layer. Transactions would be accomplished by using the standard BEGIN, COMMIT, and ROLLBACK statements. A promise-based wrapper API could be used to support async/await.

brodycj commented 3 years ago

The new plugin design has been working together with SQLCipher and PouchDB for RTI (https://www.rti.org). I will still need some time to get it ready for more widespread usage. Here are the components available and delivered so far:

The following patch is required in https://github.com/brodybits/cordova-sqlite-plugin-legacy-object-wrapper to support SQLCipher with the password key option:

index 12af61b..c2ecbbe 100644
--- a/cordova-sqlite-plugin-legacy-object-wrapper.js
+++ b/cordova-sqlite-plugin-legacy-object-wrapper.js
@@ -224,6 +224,7 @@
           console.log('path: ' + path);
           opts = {
             fullName: path,
+            key: _this.openargs.key || '',
             flags: 6
           };
           return window.sqliteBatchConnectionManager.openDatabaseConnection(opts, function(id) {

Some loose ends:

brodycj commented 3 years ago

I would like to better understand this comment if it may affect using an open SQLite connection from a thread pool: https://sqlite.org/forum/forumpost/f9d10599b6

brodycj commented 3 years ago

I have renamed the project for 2021 and pushed some updates to support named parameters (on Android, iOS, and macOS).