If explode
is true
, then items' values for this index are expected to be arrays.
Each value in an array will be added to the index, instead of the array being added as a whole.
For instance, say we're storing type User = { id: number, likedPostIds: Array<number> }
objects.
We may have an index called liked
which is intended to organize users by what posts they've liked.
If the index is not exploding, then the user { id: 1, likedPostIds: [1, 2, 3] }
will match
a query for [1, 2, 3]
but not a query for 1
, for 2
, or for 3
.
But if the index is exploding, then this same user will match a query
for each of 1
, 2
, and 3
, but not a query for [1, 2, 3]
.
Indexes come in two flavors: path indexes and derived indexes.
With a path index, items are indexed on existing properties.
For example, if we're storing array objects, we may index by .length
.
The path is stored in Index.traitPath.
With a derived index, items are indexed on calculated values.
For example, storing an array object, we may want to index by whether or not the array has a duplicate value.
Then we would index by the function (item: Array) => item.length !== new Set(item).size
(or a more efficient alternative).
This function is stored in Index.traitGetter.
If this.kind === 'derived'
, return the trait computing function.
If this.kind === 'path'
, return the trait path.
Are the values in this index required to be unique?
Test if there are any items with the given trait
Retrieve all items matching a given trait.
Get an item by trait.
Usable on unique indexes only.
Throws if no item is found.
Get an item by trait, or return something else if the item isn't found.
Usable on unique indexes only.
Select a single item by trait.
Usable on unique indexes only.
Update an item if it exists, or add a new one if it doesn't.
Allowed on unique indexes only.
Updates the trait getter on a derived index.
Only usable during a migration.
Updates the trait path on a path index.
Only usable during a migration.
Generated using TypeDoc
An index on an object store.
An index is a way of organizing stored items to be queried later. You set up an index to keep track of particular attributes of your items (such as a
.id
property). The attribute that you track is known as the trait. You can then query indexes to find items based on their traits.