| 5 | import type { UnknownRow } from '../util/type-utils.js' |
| 6 | |
| 7 | export interface KyselyPlugin { |
| 8 | /** |
| 9 | * This is called for each query before it is executed. You can modify the query by |
| 10 | * transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node} |
| 11 | * and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer} |
| 12 | * for this. |
| 13 | * |
| 14 | * If you need to pass some query-related data between this method and `transformResult` you |
| 15 | * can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key: |
| 16 | * |
| 17 | * ```ts |
| 18 | * import type { |
| 19 | * KyselyPlugin, |
| 20 | * QueryResult, |
| 21 | * RootOperationNode, |
| 22 | * UnknownRow |
| 23 | * } from 'kysely' |
| 24 | * |
| 25 | * interface MyData { |
| 26 | * // ... |
| 27 | * } |
| 28 | * const data = new WeakMap<any, MyData>() |
| 29 | * |
| 30 | * const plugin = { |
| 31 | * transformQuery(args: PluginTransformQueryArgs): RootOperationNode { |
| 32 | * const something: MyData = {} |
| 33 | * |
| 34 | * // ... |
| 35 | * |
| 36 | * data.set(args.queryId, something) |
| 37 | * |
| 38 | * // ... |
| 39 | * |
| 40 | * return args.node |
| 41 | * }, |
| 42 | * |
| 43 | * async transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>> { |
| 44 | * // ... |
| 45 | * |
| 46 | * const something = data.get(args.queryId) |
| 47 | * |
| 48 | * // ... |
| 49 | * |
| 50 | * return args.result |
| 51 | * } |
| 52 | * } satisfies KyselyPlugin |
| 53 | * ``` |
| 54 | * |
| 55 | * You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery` |
| 56 | * is not always matched by a call to `transformResult` which would leave orphaned items in the map |
| 57 | * and cause a memory leak. |
| 58 | */ |
| 59 | transformQuery(args: PluginTransformQueryArgs): RootOperationNode |
| 60 | |
| 61 | /** |
| 62 | * This method is called for each query after it has been executed. The result |
| 63 | * of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}. |
| 64 | * You can modify the result and return the modifier result. |
no outgoing calls
no test coverage detected
searching dependent graphs…