github dexie/Dexie.js v3.1.0-alpha.5
Dexie v3.1.0-alpha.5

latest releases: v4.0.0-alpha.4, v3.0.4, v4.0.0-alpha.3...
pre-release3 years ago

Improved liveQuery

liveQuery() was explained in this blog post some weeks before this release.

The new liveQuery() and the corresponding react hook useLiveQuery() have been improved using a Btree structure to track and match queried ranges against mutated ranges on primary keys and indices.

This release improves liveQuery() in the following ways:

  • Live queries are more fine-grained. In previous version, index-based queries where always rerun on any mutation. Only primary key based queries were selectively re-run. In this version, index based queries only re-run when the mutation would affect the result of that query.

    // The following query will emit new results when todoItems on that todoList are updated.
    // ...but not if a todo item on another list is updated.
    // ...but if a todo item is moved into our out from the list, the query will also emit new result.
    liveQuery(()=> db.todoItems.where({todoListId: todoList.id}).toArray())
    
    // The following query will emit new results when friends within the age range are updated.
    // ...but not if a friend outside the range is updated.
    // ...but if a friend's age is changes (moved into range or out from range), it will also emit result.
    liveQuery(()=> db.friends.where('age').between(20, 20).toArray())
    
    // Key-only queries will not emit new results for property updates - only when key is change
    liveQuery(() => db.friends.where('age').between(20,30).keys())
    liveQuery(() => db.friends.where('age').between(20,30).primaryKeys())

    count() requests may still need to emit more often on Table.put() and Table.delete() operations as we cannot detect affected keys unless the mutation is a Table.add(), Table.update() or Collection.modify(), which gives more information to DBCore about the index values of the previous object in database.

  • Rx compatible (via Rx.from()).

    import * as Rx from "rxjs";
    import { map } from "rxjs/operators";
    import { liveQuery } from "dexie";
    
    const observable = Rx.from(liveQuery(
      () => db.friends.count()
    )).pipe(
      map(friendCount => friendCount + 1)
    );

Also

  • Code cleanup and optimizations.
  • Option {allKeys: true} to bulkPut() and bulkAdd() will be equally fast as not providing that option.
  • PR 1104: dbName follows dependencies.indexedDB (II)

Don't miss a new Dexie.js release

NewReleases is sending notifications on new releases.