Last active
May 8, 2021 12:03
-
-
Save surajtruckx/81fc41253061a7b0c1b5fbe4a1ae4a1c to your computer and use it in GitHub Desktop.
Sql Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?