MikroKyselyPlugin
Implements
- KyselyPlugin
Index
Constructors
Methods
Constructors
constructor
Parameters
em: SqlEntityManager<AbstractSqlDriver<AbstractSqlConnection, AbstractSqlPlatform>>
options: MikroKyselyPluginOptions = {}
Returns MikroKyselyPlugin
Methods
transformQuery
This is called for each query before it is executed. You can modify the query by transforming its OperationNode tree provided in args.node and returning the transformed tree. You'd usually want to use an OperationNodeTransformer for this.
If you need to pass some query-related data between this method and
transformResultyou can use aWeakMapwith args.queryId as the key:import type {
KyselyPlugin,
QueryResult,
RootOperationNode,
UnknownRow
} from 'kysely'
interface MyData {
// ...
}
const data = new WeakMap<any, MyData>()
const plugin = {
transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
const something: MyData = {}
// ...
data.set(args.queryId, something)
// ...
return args.node
},
async transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>> {
// ...
const something = data.get(args.queryId)
// ...
return args.result
}
} satisfies KyselyPluginYou should use a
WeakMapinstead of aMapor some other strong references becausetransformQueryis not always matched by a call totransformResultwhich would leave orphaned items in the map and cause a memory leak.Parameters
args: PluginTransformQueryArgs
Returns RootOperationNode
transformResult
This method is called for each query after it has been executed. The result of the query can be accessed through args.result. You can modify the result and return the modifier result.
Parameters
args: PluginTransformResultArgs
Returns Promise<QueryResult<UnknownRow>>
Kysely plugin that transforms queries and results to use MikroORM entity/property naming conventions.