Skip to content

Instantly share code, notes, and snippets.

@fireflysemantics
Created January 21, 2020 23:56
Show Gist options
  • Save fireflysemantics/7b78ac8d20505e861466d96b3828e487 to your computer and use it in GitHub Desktop.
Save fireflysemantics/7b78ac8d20505e861466d96b3828e487 to your computer and use it in GitHub Desktop.
import Dexie from 'dexie';
import { IEmailAddress,
IPhoneNumber,
Contact } from './model';
export class AppDatabase extends Dexie {
public contacts: Dexie.Table<Contact, string>
public emails: Dexie.Table<IEmailAddress, string>
public phones: Dexie.Table<IPhoneNumber, string>
constructor() {
super("ContactsDatabase")
const 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 const db = new AppDatabase()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment