Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Last active May 12, 2019 20:04
Show Gist options
  • Save indatawetrust/faadb2b584dbbd220f071cbcece4e4b1 to your computer and use it in GitHub Desktop.
Save indatawetrust/faadb2b584dbbd220f071cbcece4e4b1 to your computer and use it in GitHub Desktop.
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