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: packages/docs/src/pages/docs/middleware.mdx
+41-5Lines changed: 41 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,51 @@ This is all quite simple with a call to [`use()`](/docs/reference/use):
13
13
14
14
```ts
15
15
use(userTable, async (ctx) => {
16
-
// Log the method called
17
-
console.log(ctx.action);
18
-
// Log parameters given to the method
19
-
console.log(ctx.params);
16
+
// Execute code before calling the implementation
17
+
console.log(ctx.action); // Log the method called
18
+
console.log(ctx.params); // Log parameters given to the method
20
19
21
20
// Call the native implementation
22
21
const result =awaitctx.next(...ctx.params);
22
+
23
+
// Execute code after the implementation
24
+
console.log("Everything worked!");
25
+
26
+
// Don't forget to return the result ;)
23
27
returnresult;
24
28
})
25
29
```
26
30
27
-
More info about how hooks work and what you can do with them can be found in [the reference](/docs/reference/use).
31
+
More info about how hooks work can be found in [the reference](/docs/reference/use).
32
+
33
+
## Modifying parameters
34
+
35
+
Hooks allow you to modify parameters passed to BlinkDB functions.
36
+
37
+
As an example, you can make sure that [`count`](/docs/reference/count) will always [prefer performance to accuracy](/docs/reference/count#performance):
38
+
39
+
```ts
40
+
use(userTable, async (ctx) => {
41
+
if(isAction(ctx, "count")) {
42
+
// Always pass `{ exact: false }` as an option to `count`
0 commit comments