The KyselyPlugin Interface
All plugins implement theKyselyPlugin interface:
Installing Plugins
Plugins are registered when creating a Kysely instance:Built-in Plugins
CamelCasePlugin
Converts snake_case database identifiers to camelCase in JavaScript:DeduplicateJoinsPlugin
Automatically deduplicates identical JOIN clauses:ParseJSONResultsPlugin
Automatically parses JSON columns:Creating Custom Plugins
Basic Example: Query Logger
Advanced Example: Timing Plugin
Sharing Data Between transformQuery and transformResult
Use aWeakMap with queryId as the key:
Transforming the Query AST
Use anOperationNodeTransformer to modify query structure:
Plugin Execution Order
Plugins execute in the order they’re registered:transformQuery, plugins run in order:
transformResult, plugins run in reverse:
Dynamic Plugin Management
Real-World Plugin Examples
Soft Delete Plugin
Row-Level Security Plugin
Best Practices
Use
WeakMap with queryId to share data between transformQuery and transformResult to prevent memory leaks.