Added support for secondary indices for fast lookups
Summary:
Add support for secondary indices, to allow for cheap lookups, like a set of events for a specific UI element in the events table:
```
#### getAllRecordsByIndex
Usage: `getAllRecordsByIndex({ indexedAttribute: value, indexAttribute2: value2, .... })`
This method allows fast lookups for objects that match specific attributes exactly.
Returns all items matching the specified index query.
Note that the results are unordered, unless
records have not been updated using upsert / update, in that case
insertion order is maintained.
If no index has been specified for this exact keyset in the indexQuery (see options.indices), this method will throw.
Example:
```
```
const ds = createDataSource([eatCookie, drinkCoffee, submitBug], {
key: 'id',
indices: [
['title']
['id', 'title'],
['title', 'done'],
],
});
// Find first element with title === cookie (or undefined)
const todo = ds.getFirstRecordByIndex({
title: 'cookie',
})
// Find all elements where title === cookie, and done === false
const todos = ds.getAllRecordsByIndex({
title: 'cookie',
done: false,
})
```
Reviewed By: antonk52
Differential Revision: D47396435
fbshipit-source-id: 20c4527be83532863b9b07ab20ebf20a80c3c35d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0345d7d533
commit
c8776175c3
@@ -29,6 +29,7 @@ This library builds a map-reduce inspired data processing pipeline that stores d
|
||||
* Virtualization (windowing) is built in.
|
||||
* Dynamic row wrapping is supported when rendering tables.
|
||||
* Any stable JS function can be used for sorting and filtering, without impacting performance significantly.
|
||||
* Support for secondary indices to support close to O(1) lookups for known values.
|
||||
|
||||
This library is designed with the following constraints in mind:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user