Outdated doc - ionic nativ - sqlite

on this page

ionic nativ - sqlite

let db = new SQLite(); --> throws an error. it expects param of type ‘any’

db.openDatabse(); --> throws an error. openDatabase() is not a method of SQLite.

the rest not tested.

You testing code on browser ?

yup. But i highly doubt it’s due to the browser. Cos the error is from visual studio code tslinter.

No you need debug you application .

I’m not sure what you mean. Isn’t tslinter debugging for me? it shows by definition in the plugin,

let db = new SQLite();

expects an parameter of type “any”. And but it is indeed an ts error because angular ts compiler will refuse to compile as well.

same for the second error.

I’m exactly in the same situation. Updating from beta 4 to beta-9 has entirely broken my application :confused:

In the definition there is no method called openDatabase :confused:

export declare class SQLite {
    private _objectInstance;
    databaseFeatures: any;
    constructor(config: any);
    addTransaction(transaction: any): void;
    transaction(fn: any): Promise<any>;
    readTransaction(fn: any): Promise<any>;
    startNextTransaction(): void;
    close(): Promise<any>;
    start(): void;
    executeSql(statement: string, params: any): Promise<any>;
    addSatement(sql: any, values: any): Promise<any>;
    sqlBatch(sqlStatements: any): Promise<any>;
    abortallPendingTransactions(): void;
    handleStatementSuccess(handler: any, response: any): void;
    handleStatementFailure(handler: any, response: any): void;
    run(): void;
    abort(txFailure: any): void;
    finish(): void;
    abortFromQ(sqlerror: any): void;
    static echoTest(): Promise<any>;
    static deleteDatabase(first: any): Promise<any>;

Edit: Ok, just seeing the definition I found how you must do it:

this.storage = new SQLite({
  name: 'db',
  location: '2'

And then just execute sql over the object:

Mine seems to be working now :slight_smile:

Edited again:

No is not working :frowning: My SQLite instantiated object is just undefined, I don’t know what is happening but I think it is a matter of definitions :frowning:

Same here.
I expected something like ready() method to check if db is ready after instantiating. But there is no such thing.

EDIT: It seems that changes from https://github.com/driftyco/ionic-native/commit/f1c8ce35e85d9ddebf7288e9c1abb5e70811d23d are not released yet.
This commit was made 5 days ago. 1.3.0 was published 12 days ago.
So we are about to wait.

FWIW, I use the following code:

const win:any = window; // get around plugin namespace pollution
if (win.sqlitePlugin) {
  let openparms = {
    name: _SQLITE_DB_NAME,
    location: 2, // local backup
    createFromLocation: 0
  this._db = win.sqlitePlugin.openDatabase(openparms);
} else {
  console.warn('Storage: SQLite plugin not installed, falling back to WebSQL. Make sure to install cordova-sqlite-storage in production!');
  this._db = win.openDatabase(_SQLITE_DB_NAME, '1.0', 'database', 5 * 1024 * 1024);

Hope ionic team fixed the documentation by the time it releases officially.

It’s released in 1.3.1 version, it’s ok now.

1.3.1 didn’t work for me:
Uncaught ReferenceError: PushNotification is not defined

1.3.2 is ok.

I have updated to version 1.3.2 and
(index):28 Unable to open database ReferenceError: sqlitePlugin is not defined(…)

This is the result. I’m a bit desperated with this because it breaks my entire app.

The error appears in browser and in iOS device

Are you sure the plugin is installed correctly? its normal to get this error in the browser. You could use a structure like rapropos posted a bit earlier.

It’s properly installed, or at least it seems to. It appears in ionic plugin list, I have tried to uninstall it and reinstall it but the problem persists.

The solution provided by rapropos also doesn’t work because window.sqlitePlugin just doesn’t exists :frowning: and window.openDatabase hangs my iOS emulator with a white screen of death. I don’t know which could be my problem…

I’m using version 1.4.3 of the plugin.

I’m using WKWebView, maybe it has something to do.

Are you using the livereload option?

Yes in browser, not in emulator.

Update: I have read WebSQL is not available in WKWebView!

ionic -v

cordova -v

cordova plugins
cordova-plugin-sqlite-2 1.0.4 “SQLitePlugin”

under: ionic serve
Unable to open database ReferenceError: sqlitePlugin is not defined