Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. initializeApp() {
  2. this.platform.ready().then(() => {
  3. StatusBar.styleDefault();
  4. if (window.cordova) {
  5. this.createDatabase();
  6. }
  7. });
  8. }
  9.  
  10. private createDatabase(): void {
  11. let db: SQLite = new SQLite();
  12. db.openDatabase({
  13. name: "data.db",
  14. location: "default"
  15. }).then(() => {
  16. 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) => {
  17. console.log("chats TABLE CREATED: ", chatData);
  18. 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) => {
  19. console.log("messages TABLE CREATED: ", messageData);
  20. }, (error) => {
  21. console.error("Unable to execute messages sql", error);
  22. });
  23.  
  24. }, (error) => {
  25. console.error("Unable to execute chats sql", error);
  26. });
  27. }, (error) => {
  28. console.error("Unable to open database", error);
  29. });
  30. }
  31.  
  32. constructor() {
  33. if (window.cordova) {
  34. this.openDatabase();
  35. }
  36. }
  37.  
  38. private openDatabase(): void {
  39. console.log('openDatabase');
  40. this.database.openDatabase({ name: "data.db", location: "default" }).then(() => {
  41. this.refreshChats();
  42. this.refreshMessages();
  43. }, (error) => {
  44. console.log("ERROR: ", error);
  45. });
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement