MCPcopy
hub / github.com/kysely-org/kysely / KyselyPlugin

Interface KyselyPlugin

src/plugin/kysely-plugin.ts:7–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import type { UnknownRow } from '../util/type-utils.js'
6
7export 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.

Callers 10

transformQueryMethod · 0.65
toOperationNodeMethod · 0.65
#toOperationNodeMethod · 0.65
toOperationNodeMethod · 0.65
toOperationNodeMethod · 0.65
toOperationNodeMethod · 0.65
toOperationNodeMethod · 0.65
toOperationNodeMethod · 0.65
#transformResultFunction · 0.65

Implementers 9

TestPlugintest/node/src/plugin-composition.test.
NoopPluginsrc/plugin/noop-plugin.ts
DeduplicateJoinsPluginsrc/plugin/deduplicate-joins/deduplica
HandleEmptyInListsPluginsrc/plugin/handle-empty-in-lists/handl
CamelCasePluginsrc/plugin/camel-case/camel-case-plugi
ImmediateValuePluginsrc/plugin/immediate-value/immediate-v
ParseJSONResultsPluginsrc/plugin/parse-json-results/parse-js
WithSchemaPluginsrc/plugin/with-schema/with-schema-plu
SafeNullComparisonPluginsrc/plugin/safe-null-comparison/safe-n

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…