Skip to content

Commit 728e136

Browse files
authored
Merge pull request #664 from subquery/feedback-2025-08
Clarify documentation based on feedback
2 parents 9393845 + 9257e95 commit 728e136

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

docs/indexer/build/mapping/cache.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This cache is globally accessible and is introduced alongside `logger` and `stor
66

77
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.
88

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.
11+
:::
12+
913
Following is a summary of the `Store` interface:
1014

1115
```ts

docs/indexer/build/mapping/store.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Advanced Access to the SubQuery Store
22

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+
35
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.
46

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-
:::
87

98
Following is a summary of the `Store` interface:
109

@@ -63,8 +62,12 @@ This allows you to get a record of the entity with its `id`.
6362
const id = block.block.header.hash.toString();
6463
await store.get(`TransactionEntity`, id);
6564
```
65+
## Filtering Records
6666

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
6871

6972
```ts
7073
export type GetOptions<T> = {
@@ -96,15 +99,15 @@ The store has a cache layer in order to increase performance, because of this th
9699

97100
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.
98101

99-
### Ordering
102+
#### Ordering
100103

101104
::: info Note
102105
Ordering is only available in SDK versions >= 4.0.0
103106
:::
104107

105108
By default ordering is done by `id` in ascending order.
106109

107-
### Examples
110+
#### Examples
108111

109112
Using the store directly:
110113

@@ -142,7 +145,7 @@ await TransactionEntity.getByFields([["ChainID", "in", [50, 51]]], {
142145
});
143146
```
144147

145-
## Get Records by a Single Field
148+
### Get Records by a Single Field
146149

147150
```ts
148151
export type GetOptions<T> = {
@@ -180,7 +183,7 @@ await store.getByField("TransactionEntity", "ChainID", [50, 100, 150], {
180183
});
181184
```
182185

183-
## Get First Record by Field
186+
### Get First Record by Field
184187

185188
`getOneByField(entity: string, field: string, value: any): Promise<Entity | undefined>;`
186189

@@ -202,7 +205,21 @@ const id = block.block.header.hash.toString();
202205
await store.set(`TransactionEntity`,id, {ChainID: 50, ...})
203206
```
204207

205-
## Bulk Create Records
208+
## Remove Record
209+
210+
`remove(entity: string, id: string): Promise<void>;`
211+
212+
This allows to remove a single record of the entity with its `id`.
213+
214+
```ts
215+
const id = block.block.header.hash.toString();
216+
await store.remove(`TransactionEntity`, id);
217+
```
218+
219+
## Bulk Operations
220+
These methods don't offer much in the way for performance improvements by being bulk operations, but they may provide some convenience.
221+
222+
### Bulk Create Records
206223

207224
`bulkCreate(entity: string, data: Entity[]): Promise<void>;`
208225

@@ -216,7 +233,7 @@ await store.bulkCreate(`TransactionEntity`,[
216233
])
217234
```
218235

219-
## Bulk Upsert (Create and Update) Records
236+
### Bulk Upsert (Create and Update) Records
220237

221238
`bulkUpdate(entity: string, data: Entity[], fields?: string[]): Promise<void>;`
222239

@@ -244,18 +261,8 @@ await store.bulkUpdate(`TransactionEntity`,[
244261

245262
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`.
246263

247-
## Remove Record
248-
249-
`remove(entity: string, id: string): Promise<void>;`
250-
251-
This allows to remove a single record of the entity with its `id`.
252-
253-
```ts
254-
const id = block.block.header.hash.toString();
255-
await store.remove(`TransactionEntity`, id);
256-
```
257264

258-
## Bulk Remove Record
265+
### Bulk Remove Record
259266

260267
`bulkRemove(entity: string, ids: string[]): Promise<void>;`
261268

docs/indexer/miscellaneous/ipfs.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ Your project should now be ready to deploy via IPFS to the SubQuery network.
4343

4444
## Publish to IPFS
4545

46-
### Prepare your SUBQL_ACCESS_TOKEN
47-
48-
- Step 1: Go to [OnFinality Indexer Service](https://indexing.onfinality.io/) and log in.
49-
- Step 2: Click on your profile at the top right of the navigation menu, then click on **_Refresh Token_**.
50-
- Step 3: Copy the generated token.
51-
- Step 4: To use this token:
52-
- Option 1: Add SUBQL_ACCESS_TOKEN in your environment variables. `EXPORT SUBQL_ACCESS_TOKEN=<token>` (Windows) or `export SUBQL_ACCESS_TOKEN=<token>` (Mac/Linux)
53-
- Option 2: Coming soon, `subql/cli` will support storing your SUBQL_ACCESS_TOKEN locally.
54-
5546
### How to publish a project
5647

5748
Run the following command, which will read the project's default manifest `project.ts` for the required information.

0 commit comments

Comments
 (0)