capacitor-community / sqlite

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

CapacitorSQLPlugin.CapacitorSQLiteElectron is undefined #46

Closed hardtmedia closed 3 years ago

hardtmedia commented 3 years ago

When loading the plugin for electron, as described in the readme, CapacitorSQLPlugin.CapacitorSQLiteElectron is undefined. Code Completion does not provide the suggestion for CapacitorSQLiteElectron, hence the cast to "any".

Imports:

import { Plugins } from '@capacitor/core';
import * as CapacitorSQLPlugin from '@capacitor-community/sqlite';
const { CapacitorSQLite, Device } = Plugins;

Method to select the correct plugin

private async selectSqlitePlatform() {
    console.warn('StorageService:selectSqlitePlatform')

    if (this._sqlite !== undefined) {
      console.warn('StorageService:selectSqlitePlatform -- Platform plugin seems to be loaded', this._sqlite)
    }

    // get platform name
    const info = await Device.getInfo()
    const platform = info.platform

    if (platform === "ios") {
      this._sqlite = CapacitorSQLite
    }

    else if (platform === "android") {
      this._sqlite = CapacitorSQLite

      try {
        await this._sqlite.requestPermissions()
      } catch (e) {
        // permissions declined
      }
    }

    else if (platform === "electron") {
      console.log("electron")
      this._sqlite = (CapacitorSQLPlugin as any).CapacitorSQLiteElectron // <------------ does not exist
    }

    else {
      this._sqlite = CapacitorSQLPlugin.CapacitorSQLite
    }
  }

When I try the example service from the jeep starter project, there is no distinction between the platforms and so any action results in "Not implemented on Web Platform" (when running in electron).

Also, I can find no instance of "CapacitorSQLiteElectron" in the repo, thus questioning if this (still) exists?

I am working with Ionic 5 / Angular 10, access to the Project can be provided if needed.

Should it be an issue with versions, this is my package.json

{
  "name": "",
  "version": "4.0.0",
  "author": "",
  "homepage": "",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~10.0.0",
    "@angular/core": "~10.0.0",
    "@angular/forms": "~10.0.0",
    "@angular/platform-browser": "~10.0.0",
    "@angular/platform-browser-dynamic": "~10.0.0",
    "@angular/router": "~10.0.0",
    "@capacitor-community/electron": "^1.2.3",
    "@capacitor-community/sqlite": "^2.4.2-2",
    "@capacitor/android": "^2.4.2",
    "@capacitor/core": "2.4.2",
    "@capacitor/ios": "^2.4.2",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^5.0.0",
    "ol": "^6.4.3",
    "rxjs": "~6.5.5",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1000.0",
    "@angular/cli": "~10.0.5",
    "@angular/compiler": "~10.0.0",
    "@angular/compiler-cli": "~10.0.0",
    "@angular/language-service": "~10.0.0",
    "@capacitor/cli": "2.4.2",
    "@ionic/angular-toolkit": "^2.3.0",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~3.3.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.9.5"
  },
  "description": ""
}
hardtmedia commented 3 years ago

Reading the changes in this: https://github.com/jepiqueau/angular-sqlite-app-starter/commit/a57a3f3bbddc05f8276486ea41e82d57ecae83ca

In combination with carefully reading https://github.com/capacitor-community/sqlite/issues/42 brought on the solution.

Thank you for your work :)

jepiqueau commented 3 years ago

@hartmedia Thanks for using the plugin. Sorry for this, it took times so the documentation was not up-to-date. Now it is and the app-starter was alined with the new release of the plugin. If you still find something not really feel free to tell me