Last active
March 30, 2019 23:49
-
-
Save oleersoy/6f2fdf961e4a510c035b0bf9cf29fb87 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 Dexie from 'dexie'; | |
| import {IEmailAddress, IPhoneNumber, Contact} from './model'; | |
| export class AppDatabase extends Dexie { | |
| public contacts: Dexie.Table<Contact, number>; | |
| public emails: Dexie.Table<IEmailAddress, number>; | |
| public phones: Dexie.Table<IPhoneNumber, number>; | |
| constructor() { | |
| super("ContactsDatabase"); | |
| var db = this; | |
| // | |
| // Define tables and indexes | |
| // | |
| db.version(1).stores({ | |
| contacts: '++id, firstName, lastName', | |
| emails: '++id, contactId, type, email', | |
| phones: '++id, contactId, type, phone', | |
| }); | |
| // Let's physically map Contact class to contacts table. | |
| // This will make it possible to call loadEmailsAndPhones() | |
| // directly on retrieved database objects. | |
| db.contacts.mapToClass(Contact); | |
| } | |
| } | |
| export var db = new AppDatabase(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment