Skip to main content
Version: 3.0 Alpha

Kysely Query Hooks

Introduction​

Kysely query hooks are the lowest level of interceptors in the plugin system. Since ZenStack eventually delegates all database access to Kysely, these hooks allow you to inspect and modify all SQL queries before they are sent to the database, regardless of whether they originate from the ORM query API or the query builder API.

This mechanism gives you great power to control the ORM's behavior entirely. One good example is the access policy - the access policy enforcement is entirely achieved via intercepting the Kysely queries.

To create a Kysely query hook plugin, call the $use method with an object containing a onKyselyQuery callback. The callback is triggered before each Kysely query is executed. It receives a context object containing:

  • The Kysely instance
  • The Kysely query node (SQL AST)
  • The ORM client that triggered the query
  • A "proceed query" function, which you can call to send the query to the database

Samples​

info

Kysely's QueryNode objects are low-level and not easy to process. ZenStack will provide helpers to facilitate common tasks in the future.

plugins/kysely-query-hooks.ts
Loading...
Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below