capacitor-community / sqlite

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

createConnection returns null #91

Closed JuanDeLeon closed 3 years ago

JuanDeLeon commented 3 years ago

Hey, not sure what I could be doing wrong, but the createConnection method is returning null. Here's the relevant code. It is in a try catch block, but no exceptions or error messages are being thrown at all.

import { Plugins } from "@capacitor/core";
const { CapacitorSQLite } = Plugins;
import "@capacitor-community/sqlite";
import { SQLiteConnection } from "@capacitor-community/sqlite";
const sqlite = new SQLiteConnection(CapacitorSQLite);

let res = await sqlite.echo("Hello from echo");
console.log(res.value);

const db = await sqlite.createConnection('testnew', false, 'no-encryption', 1);
console.log(db);

Package.json:

"@capacitor-community/sqlite": "^2.9.13",
    "@capacitor/android": "^2.4.6",
    "@capacitor/core": "2.4.6",
    "@capacitor/ios": "^2.4.6",

Expected the createConnection() result to not be null. Getting the following in browser, simulator, and actual device.

Captura de Pantalla 2021-03-07 a la(s) 20 09 44

UPDATE Now using the vue-sqlite-hook but still no success. Now in the browser I get "Feature not available on this platform/device." But in simulator I get "[log] - No returned connection", which comes from the vue-sqlite-hook code.

On the other hand, I ran the vue starter app and it does work fine there...

UPDATE 2 Managed to put a log in the plugin's definitions.js which yields the following. No idea why though... [log] - {"result":false,"message":"Not implemented on Web Platform"} It seems like the Plugin is executing as if I was on web platform... because I also get this exact log in Xcode console: [log] - ECHO in Web plugin {"value":"Hello from echo"}

However, the starter app shows differently in Xcode: TO JS {"value":"Hello from echo"}

macOS Catalina 10.15.7 Google Chrome, same for iOS simulator and device, both on latest iOS 14.4

JuanDeLeon commented 3 years ago

Ok, somehow, my Podfile was missing this plugin... so I just added this line and ran 'pod install' then everything worked. pod 'CapacitorCommunitySqlite', :path => '../../node_modules/@capacitor-community/sqlite'

jepiqueau commented 3 years ago

@JuanDeLeon Thanks for using the plugin. I saw that you find your way. Good luck with your development

akisoft21 commented 3 years ago

i am having same issues on android, i have imported the plugin into the main activity, but still returning null.

jepiqueau commented 3 years ago

@akisoft21 which version of the plugin are you using ? Can you share your package.json file

akisoft21 commented 3 years ago

@jepiqueau thanks so much for your response { "name": "agent", "version": "0.0.1", "author": "Ionic Framework", "homepage": "https://ionicframework.com/", "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/sqlite": "^2.9.16", "@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", "@ionic/storage-angular": "^3.0.6", "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": "An Ionic project" }

jepiqueau commented 3 years ago

@akisoft21 you should upgrade to capacitor 3 and install @capacitor-community/sqlite@next and follow the readme for native platforms. This release is fully tested for Android and iOS it is still in rc as electron has not been transfered yet.

akisoft21 commented 3 years ago

@jepiqueau thanks so much for the response but i faced this after upgrade error: package com.getcapacitor.annotation does not exist

jepiqueau commented 3 years ago

@akisoft21 dis you look at angular-sqlite-app-starter it should help you to start. You have a link to this app in the readme