Skip to content
Martin Jurča edited this page Aug 14, 2015 · 4 revisions

Most of the APIs allow for complex filtering of records. Due to its complexity, the filtering is described here, on a separate page.

The filtering options are:

No filtering

You can use null or undefined if you do not want to filter the records.

Matching a single record by key

You can match a single record by using a simple valid key value (a number, string, Date instance, or an array of the others) as filter. The filter will match the record by its key in the object store or index. The filter will match the record by the primary key if used with a query.

Matching several records by a range of primary key values

The most basic way of matching several records is by using an IDBKeyRange instance. These can be created either via the native IDBKeyRange API, or by using the KeyRange API of the object-store/KeyRange module, or by using the short-hand range() function of the object-store/KeyRange module.

Template object

A template object is a plain object of arbitrary depth. The field values of a template object must be either valid key values, key ranges, or template objects (no circular references are allowed).

The template object is then used as a template matched against the filtered records. Fields in records that are not present in the template object are ignored. Records without any of the fields in the template object do not match.

The indexed-db.es6 automatically attempts to (at least partially) convert a template object to a key range if possible to improve the performance. Parts of the template object that cannot be converted to a key range are compiled to a predicate function to improve the performance.

Predicate function

A predicate filtering function is a function that returns true if the record provided to it should be used. The predicate function accepts the following arguments:

  • the record
  • the primary key of the record
  • the index key of the record (used only with indexes)