sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

checkConnectionsConsistency() Error: Must provide a list of connection's open mode

Open andrew-lyons opened this issue 3 years ago • 9 comments

Describe the bug We are using this plugin within our own plugin, which is then being used in an angular project. I am baffled as to why this is happening, as we never had this issue before and nothing in our code, or dependency versions for this / jeep-sqlite changed.

I'm not sure if any other capacitor updates we've made would affect this. I did some digging into jeep-sqlite and the stack trace of this error and saw this starting at line 83 of @capacitor-community/sqlite/dist/esm/web.js:

@capacitor-community/sqlite version 3.5.1-2

    async checkConnectionsConsistency(options) {
        this.ensureJeepSqliteIsAvailable();
        try {
            const consistencyResult = await this.jeepSqliteElement.checkConnectionsConsistency(options);
            return consistencyResult;
        }
        catch (err) {
            throw new Error(`${err}`);
        }
    }

and when I console.log(options) prior to the jeepSqliteElement.checkConnectionsConsistency(options) I log {dbNames: []}. This then throws an error with jeep-sqlite as it is expecting another property in the options object.

Jeep sqlite code: https://github.com/jepiqueau/jeep-sqlite/blob/2afd0e1d088f6be32efeb2a8e8b164f7ddc18214/src/components/jeep-sqlite/jeep-sqlite.tsx#L610

To Reproduce We instantiate our plugin like so:

  /**
   * Opens the SQLite database.
   */
  async openDatabase(): Promise<SQLiteDBConnection> {
    console.log('***PRSGIO: openDatabase(): ', this.SQLiteDB, this.dbname);
    if (this.SQLiteDB !== undefined) {
      console.log('***PRSGIO: connection already exists, returning connection')
      return this.SQLiteDB
    }

    console.log('***PRSGIO: connection doesn\'t already exist')

    await this.initSQLitePluginService();

    const conConsistency = (await this.sqlite.checkConnectionsConsistency()).result;

    const isConnected = (await this.sqlite.isConnection(this.dbname)).result;

    if (conConsistency && isConnected) {
      this.SQLiteDB = await this.sqlite.retrieveConnection(this.dbname);
    }
    else {
      this.SQLiteDB = await this.sqlite.createConnection(this.dbname, false, 'no-encryption', 1);
    }

    await this.SQLiteDB.open();

    console.log('***PRSGIO: creating ngram tables');
    await this.createNgramTable();

    console.log('***PRSGIO: openDatabase(): ', this.SQLiteDB, this.dbname);

    return this.SQLiteDB;

  }

Expected behavior I expected the plugin to instantiate as it normally did in the past.

Screenshots If applicable, add screenshots to help explain your problem.

Screen Shot 2022-09-29 at 12 19 43 PM

Screen Shot 2022-09-29 at 12 22 46 PM

Desktop (please complete the following information):

  • OS: MacOS Monterey 12.5.1
  • Browser Chrome
  • Version 105.0.5195.125 (Official Build) (arm64)

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

andrew-lyons avatar Sep 29 '22 16:09 andrew-lyons

@andrew-lyons look at the doc in the new release there is the implementation of the read only mode so you have to provide a new area of modes. A connection can be simultaneously opened for RW read and write or RO read only so when you check for consistency you must tell which mode

jepiqueau avatar Sep 30 '22 07:09 jepiqueau

@andrew-lyons Is this fixed now on your side? if yes can you close the issue

jepiqueau avatar Oct 05 '22 06:10 jepiqueau

@jepiqueau I unfortunately can't move to capacitor 4.0, so I must make this work with version 3 (currently 3.5.2), and I don't see anywhere to provide these open modes, should this be done in the initSQLitePluginService call?

andrew-lyons avatar Oct 05 '22 13:10 andrew-lyons

@andrew-lyons keep working with a version of jeep-sqlite compatible with 3.5.2

jepiqueau avatar Oct 05 '22 15:10 jepiqueau

@andrew-lyons for 3.5.2 the jeep-sqlite version was 1.5.4 and sql.js version was 1.7.0

jepiqueau avatar Oct 05 '22 15:10 jepiqueau

@andrew-lyons Can you share your package.json file

jepiqueau avatar Oct 05 '22 15:10 jepiqueau

@jepiqueau Here is my file:

{
  "name": "spoken-pressagio",
  "version": "0.0.11",
  "description": "Spoken's mod of the pressagio lib",
  "author": "Andrew Lyons <[email protected]>",
  "repository": "https://github.com/spokenaac/spoken-pressagio.git",
  "license": "MIT",
  "keywords": [
    "typescript",
    "esbuild",
    "nlp"
  ],
  "main": "./dist/tsc/main.js",
  "types": "./dist/tsc/main.d.ts",
  "browser": "./dist/esbuild/browser.js",
  "bin": {
    "my-cli-tool": "./dist/esbuild/cli.js"
  },
  "scripts": {
    "cli": "ts-node src/cli.ts",
    "lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
    "clean": "rm -rf dist build package",
    "ts-node": "ts-node",
    "test": "",
    "docs": "typedoc --entryPoints src/main.ts",
    "md-docs": "typedoc --plugin typedoc-plugin-markdown --entryPoints src/main.ts",
    "build": "npm run copysqlwasm && tsc -p tsconfig.json",
    "build-all": "yarn clean && yarn build && yarn esbuild-node && yarn esbuild-browser",
    "esbuild-browser": "esbuild src/browser.ts --bundle --minify --sourcemap=external --outfile=dist/esbuild/browser.js",
    "esbuild-browser:dev": "esbuild src/browser.ts --bundle --outfile=dist/esbuild/browser.js",
    "esbuild-browser:watch": "esbuild src/browser.ts --bundle --watch --outfile=dist/esbuild/browser.js",
    "esbuild-node": "esbuild src/cli.ts --bundle --platform=node --minify --sourcemap=external --outfile=dist/esbuild/cli.js",
    "esbuild-node:dev": "esbuild src/cli.ts --bundle --platform=node --sourcemap=external --outfile=dist/esbuild/cli.js",
    "esbuild-node:watch": "esbuild src/cli.ts --bundle --platform=node --watch --sourcemap=external --outfile=dist/esbuild/cli.js",
    "copysqlwasm": "copyfiles -u 3 node_modules/sql.js/dist/sql-wasm.wasm src/assets"
  },
  "devDependencies": {
    "@types/node": "^15.0.1",
    "@typescript-eslint/eslint-plugin": "^4.19.0",
    "@typescript-eslint/parser": "^4.19.0",
    "esbuild": "^0.11.11",
    "eslint": "^7.22.0",
    "ts-node": "^9.1.1",
    "typedoc": "^0.23.0",
    "typescript": "^4.2.3"
  },
  "dependencies": {
    "@capacitor-community/sqlite": "^3.5.2",
    "@capacitor/cli": "^3.6.0",
    "@capacitor/core": "^3.6.0",
    "@types/websql": "^0.0.27",
    "copyfiles": "^2.4.1",
    "typedoc-plugin-markdown": "^3.12.1"
  }
}

andrew-lyons avatar Oct 05 '22 18:10 andrew-lyons

@andrew-lyons do Npm i --save [email protected] Npm i --save [email protected]

jepiqueau avatar Oct 06 '22 06:10 jepiqueau

@andrew-lyons Is this working now? if yes can you close the issue

jepiqueau avatar Oct 12 '22 17:10 jepiqueau