Overview
TheKyselyPlugin interface is the foundation for all Kysely plugins. Plugins allow you to intercept and modify queries before execution and transform results after execution.
Interface Definition
Methods
transformQuery
args.queryId- Unique identifier for the queryargs.node- The root operation node representing the query
OperationNodeTransformer to transform the query tree:
transformResult
args.queryId- Unique identifier for the query (same as intransformQuery)args.result- The query result containing rows and metadata
Sharing Data Between Methods
If you need to pass query-related data betweentransformQuery and transformResult, use a WeakMap with args.queryId as the key:
Using Plugins
Global Installation
Add plugins when creating a Kysely instance:Per-Query Installation
Apply a plugin to a single query:Built-in Plugins
Kysely provides several built-in plugins:- CamelCasePlugin - Converts snake_case to camelCase
- WithSchemaPlugin - Adds schema prefix to all tables
- ParseJSONResultsPlugin - Parses JSON strings in results
- DeduplicateJoinsPlugin - Removes duplicate joins