Last active
May 12, 2019 20:04
-
-
Save indatawetrust/faadb2b584dbbd220f071cbcece4e4b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { HttpClient } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
import { SQLite, SQLiteObject } from '@ionic-native/sqlite'; | |
/* | |
Generated class for the SqliteProvider provider. | |
See https://angular.io/guide/dependency-injection for more info on providers | |
and Angular DI. | |
*/ | |
@Injectable() | |
export class SqliteProvider { | |
db: any; | |
constructor(public http: HttpClient, public sqlite: SQLite) { | |
this.createDatabaseFile(); | |
} | |
public createDatabaseFile(): void { | |
this.sqlite.create({ | |
name: 'data.db', | |
location: 'default' | |
}) | |
.then((db: SQLiteObject) => { | |
this.db = db; | |
this.createTables(); | |
}) | |
.catch(e => console.log(e)); | |
} | |
private createTables() { | |
this.db.executeSql('create table if not exists user(id INTEGER PRIMARY KEY, username TEXT)', []) | |
.then(() => { console.log('table created..'); }) | |
.catch(e => console.log(e)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment