Skip to content

Instantly share code, notes, and snippets.

@surajtruckx
Last active May 8, 2021 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surajtruckx/81fc41253061a7b0c1b5fbe4a1ae4a1c to your computer and use it in GitHub Desktop.
Save surajtruckx/81fc41253061a7b0c1b5fbe4a1ae4a1c to your computer and use it in GitHub Desktop.
Sql Provider
import { Injectable } from '@angular/core';
import { SQLite } from '@ionic-native/sqlite';
import { Platform } from 'ionic-angular';
import { isEmpty, isNull, keys, sortBy, get, parseInt } from 'lodash';
import { browserDBInstance } from './browser';
declare var window: any;
const SQL_DB_NAME = process.env.IONIC_ENV === 'dev' ? '__broswer.db' : '__native.db';
@Injectable()
export class SqlProvider {
dbInstance: any;
constructor(public sqlite: SQLite, private platform: Platform) {
this.init();
}
async init() {
if (!this.platform.is('cordova')) {
let db = window.openDatabase(SQL_DB_NAME, '1.0', 'DEV', 5 * 1024 * 1024);
this.dbInstance = browserDBInstance(db);
} else {
this.dbInstance = await this.sqlite.create({
name: SQL_DB_NAME,
location: 'default'
});
}
}
}
@mitesh-shah
Copy link

openDatabase is not available

@surajair
Copy link

@mitesh-shah
Copy link

@surajair
Yes, I am referring that only.
In that there is a line -> let db = window.openDatabase(SQL_DB_NAME, '1.0', 'DEV', 5 * 1024 * 1024);

In that line openDatabase not found for type window

@surajair
Copy link

Please try this in chrome browser. I will update it in post too

@mitesh-shah
Copy link

I am trying in chrome only.

But, this error is coming before ionic serve.

It's a compilation error.

@surajair
Copy link

This setup was done on ionic 3. There are package changes in ionic 4. You might have to make some changes. Can you post exact error here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment