You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/indexer/build/mapping/cache.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,10 @@ This cache is globally accessible and is introduced alongside `logger` and `stor
6
6
7
7
The cache provides two primary methods for interacting with the cache: `set()` and `get()`. These methods allow you to store data in the cache and retrieve it, respectively.
8
8
9
+
::: warning Important
10
+
The cache isn't aware of reindexing because of block forks when indexing unfinalized blocks. Make sure the data you store in the cache takes this into consideration.
Copy file name to clipboardExpand all lines: docs/indexer/build/mapping/store.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,9 @@
1
1
# Advanced Access to the SubQuery Store
2
2
3
+
The SubQuery SDK will generate classes for your entities with the codegen step. These classes provide a simpler, better typed interface for interacting with the store. However there are times where you may need to access the store directly such as performing bulk operations.
4
+
3
5
The SubQuery store is an injected class that allows users to interact with records in the database from within mapping functions. This will come handy when user demands using multiple entity records as the parameters in the mapping function, or create/update multiple records in a single place.
4
6
5
-
::: tip Note
6
-
Note that there are additional methods autogenerated with your entities that also interact with the store. Most users will find those methods sufficient for their projects.
7
-
:::
8
7
9
8
Following is a summary of the `Store` interface:
10
9
@@ -63,8 +62,12 @@ This allows you to get a record of the entity with its `id`.
63
62
const id =block.block.header.hash.toString();
64
63
awaitstore.get(`TransactionEntity`, id);
65
64
```
65
+
## Filtering Records
66
66
67
-
## Get Records by Fields
67
+
To filter records by fields other than the ID, you NEED to set an [@index](../graphql#indexing) on the field in your GraphQl schema otherwise there will be a runtime error when querying the data.
68
+
Once the index has been added, you can run codegen and it will create convenience methods on your entity classes to filter by fields.
69
+
70
+
### Get Records by Fields
68
71
69
72
```ts
70
73
exporttypeGetOptions<T> = {
@@ -96,15 +99,15 @@ The store has a cache layer in order to increase performance, because of this th
96
99
97
100
Only fields with an index can be filtered on and an error will be thrown if the fields are not indexed. To add an index the projects graphql schema will need to be updated to include [@index](/build/graphql.html#indexing) decorators.
98
101
99
-
### Ordering
102
+
####Ordering
100
103
101
104
::: info Note
102
105
Ordering is only available in SDK versions >= 4.0.0
103
106
:::
104
107
105
108
By default ordering is done by `id` in ascending order.
Please note, this fields feature is not working currently with any automated historical indexing. It will overwrite all attributes. To disable automated historical indexing, please enable `--disable-historical=true` parameter on `subql-node`.
0 commit comments