capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
503 stars 121 forks source link

Cannot find database when launched in Electron #421

Closed saintsatplay2015 closed 1 year ago

saintsatplay2015 commented 1 year ago

Describe the bug Following errors are present when launching Ionic/Angular application with "@capacitor-community/sqlite": "^5.0.0" and "@capacitor-community/electron": "^4.1.2":

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'

Error: Uncaught (in promise): Error: The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.
Error: The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.

To Reproduce Steps to reproduce the behavior:

Create the application in Ionic 7/Angular 16 using the following steps:

ionic start ionic-sqlite blank --type=angular
cd ./ionic-sqlite/
npm run build
npm install --save @capacitor-community/electron
npx cap add @capacitor-community/electron

// Change into Electron directory and install node packages
cd ..
npm install --save @journeyapps/sqlcipher
npm install --save jszip
npm install --save node-fetch@2.6.7
npm run build --prod
cd ..
npm install --save @capacitor-community/sqlite
npm install --save @capacitor/camera
npm install --save @ionic/pwa-elements

// Sanity check to ensure ALL modules are installed that should be
cd electron 
npm install
npm run build --prod

cd ..
npm run build --prod
npx cap sync @capacitor-community/electron
npx cap copy @capacitor-community/electron
npx cap open @capacitor-community/electron

Expected behavior I believe (perhaps incorrectly?) that I have imported the correct modules and followed the correct steps to be able to use the sqlite plugin within an Ionic 7 application launched as an Electron desktop app via the @capacitor-community/electron plugin.

When I perform a build and publish the application to electron for testing on my system using the following commands:

npm run build --prod
npx cap sync @capacitor-community/electron
npx cap open @capacitor-community/electron

The project is built, with no errors in the Ionic CLI, and launched as an Electron application but multiple errors are reported in the developer console of the Electron browser environment - please see attached screenshots below.

Screenshots

The errors thrown up when the application is launched in an Electron environment:

electron-sqlite-errors

The electron build source files that are present:

electron-environment-source

The capacitor configuration file copied to Electron on capacitor sync: Electron-capacitor-configuration

Desktop (please complete the following information):

Additional context Package.json file:

  "name": "ionic-sqlite",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^16.0.0",
    "@angular/common": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/core": "^16.0.0",
    "@angular/forms": "^16.0.0",
    "@angular/platform-browser": "^16.0.0",
    "@angular/platform-browser-dynamic": "^16.0.0",
    "@angular/router": "^16.0.0",
    "@capacitor-community/electron": "^4.1.2",
    "@capacitor-community/sqlite": "^5.0.0",
    "@capacitor/app": "5.0.2",
    "@capacitor/camera": "^5.0.2",
    "@capacitor/core": "5.0.4",
    "@capacitor/haptics": "5.0.2",
    "@capacitor/keyboard": "5.0.2",
    "@capacitor/status-bar": "5.0.2",
    "@ionic/angular": "^7.0.0",
    "@ionic/pwa-elements": "^3.1.1",
    "ionicons": "^7.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.0",
    "@angular-eslint/builder": "^16.0.0",
    "@angular-eslint/eslint-plugin": "^16.0.0",
    "@angular-eslint/eslint-plugin-template": "^16.0.0",
    "@angular-eslint/schematics": "^16.0.0",
    "@angular-eslint/template-parser": "^16.0.0",
    "@angular/cli": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/compiler-cli": "^16.0.0",
    "@angular/language-service": "^16.0.0",
    "@capacitor/cli": "5.0.4",
    "@ionic/angular-toolkit": "^9.0.0",
    "@types/jasmine": "~4.3.0",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "eslint": "^7.26.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~4.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "ts-node": "^8.3.0",
    "typescript": "~5.0.2"
  },
  "description": "An Ionic project"
}

Does the Electron version need to mirror the Web set up for SQLite and use the jeep-sqlite plugin?

I could not see anything in the Electron documentation for the SQLite plugin that stated this was a requirement yet the error, when published to Electron, seems to suggest that this is the case??

I just need to clarify that I haven't missed any vital steps in getting this plugin to work with Electron, that the documentation isn't incomplete or that there isn't a bug here.

It's likely a bone-headed mistake on my part but I really appreciate any help that can be provided here :)

jepiqueau commented 1 year ago

@saintsatplay2015 you just forgot to do after the run build to do npx cap copy @capacitor-community/electron.

jepiqueau commented 1 year ago

@saintsatplay2015 By the way i usually update the package.json of the electron folder to:

  "dependencies": {
    "@capacitor-community/electron": "^4.1.2",
    "@capacitor-community/sqlite": "^5.0.0",
    "@journeyapps/sqlcipher": "^5.3.1",
    "chokidar": "~3.5.3",
    "electron-is-dev": "~2.0.0",
    "electron-serve": "~1.1.0",
    "electron-unhandled": "~4.0.1",
    "electron-updater": "~5.0.1",
    "electron-window-state": "~5.0.3",
    "jszip": "^3.10.1",
    "node-fetch": "2.6.7"
  },
  "devDependencies": {
    "electron": "^22.0.0",
    "electron-builder": "24.0.0",
    "electron-rebuild": "^3.2.7",
    "typescript": "~4.3.5"
  },

So you delete the node_modules folder and the package-lock.json and redo

npm install
npm build
saintsatplay2015 commented 1 year ago

@jepiqueau Thanks for your prompt reply, much appreciated.

I made the changes that you suggested in the electron folder - deleting the node_modules and package.lock.json files, updating the package.json file to the dependencies and devDependencies that you listed and saved those before running npm install and npm run build.

No problem there.

Changing back to the parent ionic project root directory and running the following commands:

npm run build --prod
npx cap copy @capacitor-community/electron
npx cap open @capacitor-community/electron

Unfortunately the same errors are still present.

The app is launched but the electron develop console consistently displays the following:

electron-sqlite-errors

Does the Electron version need the jeep-sqlite plugin?

I have not installed this, nor made any configurations relating to this, as I thought this applied purely to web only.

saintsatplay2015 commented 1 year ago

I have noticed an issue with one of the node module dependency errors reported in the previous screen capture:

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node

When I check the electron directory for this path I get the following:

/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-x64/node_sqlite3.node

The installed binding directory is napi-v6-darwin-x64 NOT napi-v6-darwin-arm64.

Is this an issue related with MacOS Ventura/M1 chip MacBook architecture??

Screenshot 2023-05-26 at 18 05 08

jepiqueau commented 1 year ago

@saintsatplay2015 electron does not need jeep-sqlite component (only web). I do not have a M1 chip so it is certainly due to this as i tested on a ionic7 app and it works

saintsatplay2015 commented 1 year ago

@jepiqueau Thanks for the reply.

I have no doubts that the plugin works (I have used this many times in the previous 2 years and appreciate your contributions to the wider development community).

So the issue relates to the incorrect architecture being installed or detected for the sqlcipher package when it comes to being installed on an M1 MacBook pro?

Do you know of any workaround for this?

I suspect this may become an issue for other M1 MacBook users (possibly even M2 chips too).

jepiqueau commented 1 year ago

@saintsatplay2015 i just publish ionic7-angular-sqlite-starter using Ionic 7 Angular 16 and Capacitor 5. See if it is working I was reluctant to put back the encryption for Electron due to the use of @journeyapps/sqlcipher which was causing some issues but i was pushed by the developer community to do so. Are you using database encryption?

jepiqueau commented 1 year ago

@saintsatplay2015 I just find this sqlcipher-issue#413

saintsatplay2015 commented 1 year ago

@jepiqueau Thanks for the updates. I'll check these out and keep you informed as to progress with (hopefully) resolving this situation.

To answer your previous question - I am not currently using database encryption and have no immediate plans to do so.

I also appreciate that you might be caught between a rock and a hard place with the developer community and its requests so many thanks for your time and assistance. It does NOT go unappreciated believe me.

saintsatplay2015 commented 1 year ago

@saintsatplay2015 I just find this sqlcipher-issue#413

Yes, I saw this yesterday. I also came across this which is probably not useful in the context of this plugin (but appears to relate to M1 chip related architecture issue): https://stackoverflow.com/questions/72553650/how-to-get-node-sqlite3-working-on-mac-m1

jepiqueau commented 1 year ago

@saintsatplay2015 Was it working fine wit the release 4.6.3 on the M1 MacBook? Have you try running the 4.8.0 or 5.0.0 on a Intel based MacBook? is that working?

jepiqueau commented 1 year ago

@saintsatplay2015 If it works on Intel based MacBook can you rename the issue and 4.6.3 is not running on M1 MacBook, can you rename the issue M1 MacBook - Cannot find ...

saintsatplay2015 commented 1 year ago

@jepiqueau installed and ran the Ionic 7/Angular/SQLite starter app.

This runs fine on ionic serve in the browser.

Running the following command:

npm run electron:start

Results in the following error thrown up in the console:


For help, see: https://nodejs.org/en/docs/inspector
in setupCapacitorElectronPlugins
Error: Cannot find module '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'
Require stack:
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:963:15)
    at n._resolveFilename (node:electron/js2c/browser_init:2:109751)
    at Module._load (node:internal/modules/cjs/loader:811:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1035:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1141:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1196:10)
    at Module.load (node:internal/modules/cjs/loader:1011:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js',
    undefined
  ]
}```

Once again this is running an Apple M1 MacBook Pro using Venture 13.4 OS.
saintsatplay2015 commented 1 year ago

This appears to relate, once again, with the incorrect path of the directory that is being published within the SQL Cipher node module: m1-chip-issue

The installed binding directory is napi-v6-darwin-x64 NOT napi-v6-darwin-arm64 (which is the error being thrown in the console).

jepiqueau commented 1 year ago

@saintsatplay2015 you should raise this issue in @journeyapps/sqlcipher

saintsatplay2015 commented 1 year ago

@jepiqueau Will do - as I am also experiencing almost the same issue with the incorrect directory not being published on the following system with the Ionic 7/Angular/SQLite starter app:

In this instance, when running the npm run electron:start command I get the following error:

intel-chip-mac-issue-1

However this time there is NO directory being generated in the location where the error occurs:

intel-chip-mac-issue-2

I'll raise this will @journeyapps/sqlcipher and see what can be done.

Will post updates here (as surely I can't be the only one experiencing this?)

saintsatplay2015 commented 1 year ago

Raised an issue regarding this bug here: https://github.com/journeyapps/node-sqlcipher/issues/111

saintsatplay2015 commented 1 year ago

@jepiqueau Thanks for your help - I appreciate this is NOT directly your issue (software dependencies can be such a headache to navigate).

It doesn't seem like there's any recent development on the sqlcipher project (2 years ago was the last update) and response to user issues is patchy to say the least.

That doesn't fill me with a lot of confidence for finding resolution to this issue (hopefully I'm wrong on this point).

If there is no response from the maintainer(s) of the project what steps would you recommend going forwards to resolve this issue? I suspect that I can't be the only developer experiencing this with trying to create electron builds on Mac?

jepiqueau commented 1 year ago

@saintsatplay2015 i agree so that why i remove it 2years ago. But i was under the pressure of some developers to put it back. See if someone will look at it. Would may be i should look at 2 version one encrypted and one not?

saintsatplay2015 commented 1 year ago

@jepiqueau I appreciate you're caught between a rock and a hard place with trying to satisfy various demands on your time (who would be a developer? :D)

I'll keep you updated as to any possible response/progress from the SQL Cipher maintainer(s).

In the meantime if you wouldn't mind acting on your suggestion - to look at one version encrypted and the other version unencrypted - maybe that will provide some insight?? It can't hurt right!

Thanks once again for your prompt replies/assistance - they are greatly appreciated.

saintsatplay2015 commented 1 year ago

Tried downgrading the version of sqlcipher in the electron package.json file down to 5.2.0:


> npm run build && electron --inspect=5858 ./

> ionic7-angular-sqlite-starter@1.0.0 build
> tsc && electron-rebuild

⠹ Building module: sqlcipher, Completed: 0  CC(target) Release/obj.target/nothing/../../node-addon-api/nothing.o
  LIBTOOL-STATIC Release/nothing.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlcipher-amalgamation-3033000/sqlite3.c
/bin/sh: python: command not found
make: *** [Release/obj/gen/sqlcipher-amalgamation-3033000/sqlite3.c] Error 127
Error: `make` failed with exit code: 2
    at ChildProcess.onExit (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/node-gyp/lib/build.js:203:23)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher'

Error: node-gyp failed to rebuild '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher'
    at ChildProcess.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@electron/rebuild/lib/module-type/node-gyp/node-gyp.js:118:24)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)`

Different error this time round - but same result.
saintsatplay2015 commented 1 year ago

Similar error to that with the latest version of SQL Cipher when downgrading to 5.3.0:


> ionic7-angular-sqlite-starter@1.0.0 electron:start
> npm run build && electron --inspect=5858 ./

> ionic7-angular-sqlite-starter@1.0.0 build
> tsc && electron-rebuild

✔ Rebuild Complete
Debugger listening on ws://127.0.0.1:5858/2a7fd910-99b3-4c94-8014-417220299866
For help, see: https://nodejs.org/en/docs/inspector
in setupCapacitorElectronPlugins
Error: Cannot find module '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'
Require stack:
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:963:15)
    at n._resolveFilename (node:electron/js2c/browser_init:2:109751)
    at Module._load (node:internal/modules/cjs/loader:811:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1035:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1141:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1196:10)
    at Module.load (node:internal/modules/cjs/loader:1011:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js',
    undefined
  ]
}
` 
tobiasmuecksch commented 1 year ago

Hi, I'm experiencing the very same bug.

But i was under the pressure of some developers to put it back. I don't understand, why would someone want you to add a broken tool? After my last upgrade of this plugin I was forced to install this cipher-crap. Since then, my app stopped working on windows and linux.

@jepiqueau I highly recommend to remove this dependency asap, since it seems to be abandoned.

tobiasmuecksch commented 1 year ago

I've also asked the developers to mark the project as abandoned https://github.com/journeyapps/node-sqlcipher/issues/112

tobiasmuecksch commented 1 year ago

If you don't want to remove it; maybe you can change the code, that the node-sqlcipher module is only imported, when encryption is actually used by the app. Then I would have to install this broken lib and my app would start woking on windows again.

jepiqueau commented 1 year ago

@tobiasmuecksch this is what i am doing right now the developper will have the choice between sqlite3 without encryption and @journeyapps/sqlcipher with encryption i am not confident in using a code which is not maintained

tobiasmuecksch commented 1 year ago

@jepiqueau Thank you so much! That's a great solution 😄

jepiqueau commented 1 year ago

@saintsatplay2015 @tobiasmuecksch the new release 5.0.3 is doing this. This version allows to use @journeyapps/sqlcipher or sqlite3 depending on the value of the new parameter electronIsEncryption in the capacitor.config.ts

saintsatplay2015 commented 1 year ago

@jepiqueau I will get some time to test this over the next few days and let you know the outcome. Thanks for all your hard work and assistance with this issue - much appreciated!

saintsatplay2015 commented 1 year ago

@jepiqueau Have recreated a new project and followed the instructions listed here: https://github.com/capacitor-community/sqlite and here: https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md (as I want to be able to run the application across electron and web).

In the browser I get the following error complaining about the jeep-sqlite element not being present in the DOM:

Screenshot 2023-06-17 at 17 47 09

Yet this element has been added/saved to the app.component.html file like so:

<ion-app>
  <ion-router-outlet></ion-router-outlet>
  <jeep-sqlite *ngIf="isWeb"></jeep-sqlite>
</ion-app>

The jeep-sqlite package is also installed:

Screenshot 2023-06-17 at 17 45 36

I have also ensured that the sql-wasm.wasm file is copied to the src/assets directory:

Screenshot 2023-06-17 at 17 45 59

Electron issues

When running in electron I get the following errors:

Screenshot 2023-06-17 at 17 37 01

For some reason the sqlcipher package is being referenced in the previously listed error - despite my having set the electronIsEncryption key to false (see capacitor.config.ts file below) - and is throwing the same issue as previously reported (with incorrect system folder being referenced).

This is the actual system path that exists in the app:

Screenshot 2023-06-17 at 17 58 32

It seems strange that sqlcipher is being requested even with the electronIsEncryption key set to false.

To confirm - the preload.js file is present in the electron/src directory:

Screenshot 2023-06-17 at 17 56 34

The application capacitor.config.ts file contains the following plugins configuration:

plugins: {
    CapacitorSQLite: {
      iosDatabaseLocation: 'Library/CapacitorDatabase',
      iosIsEncryption: true,
      iosKeychainPrefix: 'angular-sqlite-app-starter',
      iosBiometric: {
        biometricAuth: false,
        biometricTitle : "Biometric login for capacitor sqlite"
      },
      androidIsEncryption: true,
      androidBiometric: {
        biometricAuth : false,
        biometricTitle : "Biometric login for capacitor sqlite",
        biometricSubTitle : "Log in using your biometric"
      },
      electronIsEncryption: false,
      electronWindowsLocation: "C:\\ProgramData\\CapacitorDatabases",
      electronMacLocation: "/Volumes/Development_Lacie/Development/Databases",
      electronLinuxLocation: "Databases"
    }
  }

The electron/package.json installed dependencies are as follows:

"dependencies": {
    "@capacitor-community/electron": "^4.1.1",
    "@capacitor-community/sqlite": "^5.0.3",
    "@journeyapps/sqlcipher": "^5.3.1",
    "chokidar": "~3.5.3",
    "electron-is-dev": "~2.0.0",
    "electron-serve": "~1.1.0",
    "electron-unhandled": "~4.0.1",
    "electron-updater": "~5.0.1",
    "electron-window-state": "~5.0.3",
    "jszip": "^3.10.1",
    "node-fetch": "^2.6.7",
    "sqlite3": "^5.1.6"
  },
  "devDependencies": {
    "@types/sqlite3": "^3.1.8",
    "electron": "^19.0.0",
    "electron-builder": "~22.14.13",
    "electron-rebuild": "^3.2.7",
    "typescript": "~4.3.5"
  },

Have I overlooked something here with the latest plugin version or is this a bug?

jepiqueau commented 1 year ago

@saintsatplay2015 can you share the project on github

jepiqueau commented 1 year ago

@saintsatplay2015 what i did work well for Mac Intel based processor but i understand that this does not work with M1 based processor as the build is building with @journeyapps/sqlcipher even if electronIsEncryption is set to false.so i do not see how i can proceed further. For the Web it should work so as i said share your app

tobiasmuecksch commented 1 year ago

I'm also working with a M1 Mac. For me this will be a big problem.

tobiasmuecksch commented 1 year ago

@journeyapps/sqlcipher is unmaintained, partially broken and will cause more and more problems in the future. I don't see any good reasons to keep it in this plugin anyways. It will only cost time and effort, with no real benefit.

Alternatively if you really need sql encryption, maybe https://github.com/m4heshd/better-sqlite3-multiple-ciphers is the better option? (Disclaimer: I don't know for sure, because I haven't tested this lib).

jepiqueau commented 1 year ago

@tobiasmuecksch i tested https://github.com/m4heshd/better-sqlite3-multiple-ciphers in a separate pure Electron App and it works. It need a complete rewrite of the electron plugin of @capacitor-community/sqlite. Required quite a work. Is it worse to do this knowing that @capacitor-community/electron is not really maintained despite what Mike Summerfeldt said

jepiqueau commented 1 year ago

@saintsatplay2015 @tobiasmuecksch i publish this test-electron-better-sqlite; Can you please clone it install it and run

npm run rebuild
npm run start

and tell me if it works on a M1 or M2 Mac

tobiasmuecksch commented 1 year ago

@jepiqueau Well, I had to create the databases folder first (mkdir src/databases) but it works as expected 😄👍

image

MacOS Ventura 13.4 MacBook Pro with M1 Pro

jepiqueau commented 1 year ago

@tobiasmuecksch thanks for the positive test i will look at how to implement it. That will take some time. Are you going to use encryption yourself.

tobiasmuecksch commented 1 year ago

@jepiqueau No, as of now I'm not planning to use encryption. But I can help testing it anyways.

switching to better-sqlite might be a good option for non-encrypted apps too, because according to their docs, it's much faster than sqlite3

jepiqueau commented 1 year ago

@tobiasmuecksch i am from this morning making the move. Yes i would like your help for testing before i launch it

jepiqueau commented 1 year ago

@tobiasmuecksch i worked already 2 full days on it but it is not a simple that i thought. Better-sqlite3 do not take the "value" in the insert statement or update statement it takes only 'value' otherwise you get column value not found which was not the case with sqlite3. So that has a big repercution in the code to allow it. I will need to restart from scratch which will take time to make it robust

jepiqueau commented 1 year ago

@tobiasmuecksch @saintsatplay2015 I just release a beta version with better-sqlite3. Can you please test it and revert to me npm i --save @capacitor-community/sqlite@better go to the electron folder of your app cd electron npm install --save better-sqlite3-multiple-ciphers npm install --save electron-json-storage npm install --save jszip npm install --save node-fetch@2.6.7 npm install --save-dev @types/better-sqlite3 npm install --save-dev @types/electron-json-storage

tobiasmuecksch commented 1 year ago

@jepiqueau I will try my best to test it until Friday. Will it work with already existing databases?

jepiqueau commented 1 year ago

@tobiasmuecksch yes it should

jepiqueau commented 1 year ago

@tobiasmuecksch thanks for your contribution i went really through all the code si i could have miss something i test it with angular-sqlite-app-starter which contains tests for all fix i had to do in the past

tobiasmuecksch commented 1 year ago

My first tests look really fine. I will now add it to my app and test it.

tobiasmuecksch commented 1 year ago

Building an electron release fails for me. I am working with a MacBook Pro M1

image
tobiasmuecksch commented 1 year ago

I've tried npm i --save better-sqlite3-multiple-ciphers --build-from-source --target_arch=arm64 --fallback-to-build but that didn't help...

tobiasmuecksch commented 1 year ago

I guess it doesn't have to do with the M1 chip, because I can't even build a windows binary. That's odd...

jepiqueau commented 1 year ago

@tobiasmuecksch i installed the latest release of electron, electron-builder & electron-rebuild

  "devDependencies": {
    "@types/better-sqlite3": "^7.6.4",
    "@types/electron-json-storage": "^4.5.0",
    "electron": "^25.2.0",
    "electron-builder": "^24.4.0",
    "electron-rebuild": "^3.2.9",
    "typescript": "~4.3.5"
  },

it seems to go further but it ask me for the git url so i fill that with the git url of the app but i am not sure of this and then i got Error: GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN". As i never went to that process of publishing an app can you explain me this in detail.