Skip to content

Instantly share code, notes, and snippets.

@oleersoy
Last active March 30, 2019 23:49
Show Gist options
  • Select an option

  • Save oleersoy/6f2fdf961e4a510c035b0bf9cf29fb87 to your computer and use it in GitHub Desktop.

Select an option

Save oleersoy/6f2fdf961e4a510c035b0bf9cf29fb87 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, 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