Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- initializeApp() {
- this.platform.ready().then(() => {
- StatusBar.styleDefault();
- if (window.cordova) {
- this.createDatabase();
- }
- });
- }
- private createDatabase(): void {
- let db: SQLite = new SQLite();
- db.openDatabase({
- name: "data.db",
- location: "default"
- }).then(() => {
- db.executeSql("CREATE TABLE IF NOT EXISTS chats (_id TEXT PRIMARY KEY, memberIds TEXT, title TEXT, subTitle TEXT, picture TEXT, lastMessageId TEXT, lastMessageCreatedAt DATE)", {}).then((chatData) => {
- console.log("chats TABLE CREATED: ", chatData);
- db.executeSql("CREATE TABLE IF NOT EXISTS messages (_id TEXT PRIMARY KEY, chatId TEXT, senderId TEXT, ownership TEXT, content TEXT, createdAt DATE, changeDate BOOLEAN, readByReceiver BOOLEAN)", {}).then((messageData) => {
- console.log("messages TABLE CREATED: ", messageData);
- }, (error) => {
- console.error("Unable to execute messages sql", error);
- });
- }, (error) => {
- console.error("Unable to execute chats sql", error);
- });
- }, (error) => {
- console.error("Unable to open database", error);
- });
- }
- constructor() {
- if (window.cordova) {
- this.openDatabase();
- }
- }
- private openDatabase(): void {
- console.log('openDatabase');
- this.database.openDatabase({ name: "data.db", location: "default" }).then(() => {
- this.refreshChats();
- this.refreshMessages();
- }, (error) => {
- console.log("ERROR: ", error);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement