Skip to content

After query event hook#33

Merged
Brayden merged 1 commit intomainfrom
bwilmoth/after-query-hook
Nov 6, 2024
Merged

After query event hook#33
Brayden merged 1 commit intomainfrom
bwilmoth/after-query-hook

Conversation

@Brayden
Copy link
Member

@Brayden Brayden commented Nov 6, 2024

Purpose

Exposing a new hook that is automatically called after a query execution has happened. This hook allows users to place custom logic to handle the results before they are returned back to the user. Situations where this may be useful is when dealing with PII and wanting to verify no information is sent back to the client that shouldn't, or maybe when you want to track how much data is being passed back to the user, audit logs, or more.

You may notice in this PR that we now pass the Env around as well so the afterQuery function has access to it. This allows developers to be able to create other Workers to handle the logic, and this piece of the code can use the Env to access those service bindings. Helps encourage separation of concern code structure.

Tasks

  • Expose an afterQuery function that can manipulate or observe query results before sending back to client.

Verify

  • Verify existing queries work correctly still
curl --location 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/query' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-Type: application/json' \
--data '{
    "sql": "SELECT * FROM users WHERE user_id=? OR name=?;",
    "params": [1, "Bob"]
}'

Before

After

@Brayden Brayden self-assigned this Nov 6, 2024
@Brayden Brayden added the enhancement New feature or request label Nov 6, 2024
@Brayden Brayden merged commit 3c8352b into main Nov 6, 2024
@Brayden Brayden deleted the bwilmoth/after-query-hook branch November 6, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant