Dexie v4.0.0-alpha.1
Pre-release
Pre-release
dfahlander
released this
05 Jan 01:23
·
457 commits
to master
since this release
The initial release on 4.0. Currently pretty much identical to 3.2.1+ but with:
- More precise typings for Collection.modify() and Table.update() using template literal types for keyPaths.
- Typings: Table.add() and Table.put() won't require methods to be present on the object to add. Allows for adding POJO objects rather than having to construct the full class to add a row.
- Typings of Table generic: A property name can be used as 2nd generic argument (TKey) rather than the direct type. This will infer the key type from the type of that property and make it optional in Table.add() and Table.put() (see sample below)
- New class exported class
Entity
that can be optionally used as a base class in order to resolve dependency issues when mapping tables to classes. A subclass of Entity has a private propertythis.db
which is the Dexie instance it originates from.Entity
subclasses are not meant to be constructed by application code.export class Friend extends Entity<FriendsDB> { id!: number; name!: string; age!: number; birthday() { return this.db.friends.update(this.id, friend => ++friend.age); } } export class FriendsDB extends Dexie { friends!: Table<Friend, 'id'>; constructor() { super("FriendsDB"); this.version(1).stores({ friends: '++id, name, age' }); this.friends.mapToClass(Friend); } }