capacitor-community / sqlite

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

Electron: No handler registered for 'CapacitorSQLite-createConnection' #380

Closed ws-rush closed 1 year ago

ws-rush commented 1 year ago

Describe the bug I test electron with sqlite plugin, I use vue as framework and implement all steps in readme file (specifically Electron Quirks), but I still get this error `Uncaught (in promise) Error: Error invoking remote method 'CapacitorSQLite-createConnection': No handler registered for 'CapacitorSQLite-createConnection'

I use vue 3.2 with vite 4 and capacitor 4

code

import { createApp } from 'vue'
import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite"
import App from './App.vue'

import './assets/main.css'

window.addEventListener("DOMContentLoaded", async () => {
    const sqlite = new SQLiteConnection(CapacitorSQLite)
    const app = createApp(App)

    const db = await sqlite.createConnection("db_tab3", false, "no-encryption", 1)
    console.log(`after create/retrieveConnection ${JSON.stringify(db)}`);
    app.mount('#app')
})

Desktop (please complete the following information):

jepiqueau commented 1 year ago

@ws-rush Look at vite-vue-sqlite-app which is a complete set-up for Vite 4.0 Vue3.2 & Capacitor 4. Hope this will help you to start. if you do not need Web, iOS and Android just remove the necessary folder and lines in the main.ts for Web

ws-rush commented 1 year ago

thank you, I missed plugin config I will make PR fro README file

{
  "appId": "com.example.app",
  "appName": "cap",
  "webDir": "dist",
  "bundledWebRuntime": false,
  "plugins": {
    "CapacitorSQLite": {
      "iosDatabaseLocation": "Library/CapacitorDatabase",
      "iosIsEncryption": false,
      "iosKeychainPrefix": "cap",
      "iosBiometric": {
        "biometricAuth": false,
        "biometricTitle" : "Biometric login for capacitor sqlite"
      },
      "androidIsEncryption": false,
      "androidBiometric": {
        "biometricAuth" : false,
        "biometricTitle" : "Biometric login for capacitor sqlite",
        "biometricSubTitle" : "Log in using your biometric"
      },
      "electronWindowsLocation": "C:\\ProgramData\\CapacitorDatabases",
      "electronMacLocation": "YOUR_VOLUME/CapacitorDatabases",
      "electronLinuxLocation": "Databases"
    }
  }
}