Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log all generated queries with log-query=full #3934

Open
steve-chavez opened this issue Mar 5, 2025 · 1 comment
Open

Log all generated queries with log-query=full #3934

steve-chavez opened this issue Mar 5, 2025 · 1 comment
Labels

Comments

@steve-chavez
Copy link
Member

steve-chavez commented Mar 5, 2025

Problem

Currently log-query doesn't log:

Solution

Log all generated queries for log-query = full.

Implementation details

  • log-query was added with some problems as mentioned on feat: log SQL query commands to stderr #3904 (comment)
  • To implement this cleanly, I think we need to stop using Hasql.Snippet in our internal modules and only use it at the top level (App.hs). This would have the nice side-effect of making our query generation "pure" too.
  • Then we would have something like:
  apiReq    <- ApiRequest.userApiRequest conf req body sCache
  plan      <- Plan.actionPlan iAction conf apiReq sCache
  queries   <- Statement.generateSQL plan
  -- here we can now log the queries as they would be simple `ByteString`s
  resultset <- Decoders.decode $ -- since generateSQL won't generate Hasql.Snippet, we would now need an explicit decoding step (it would be good to expose this as a new timing too)
               Query.execute queries $ -- here we now execute it with Hasql
 -- then build the response as usual

-- code simplified from https://github.com/PostgREST/postgrest/blob/d0173e71923e15b412fd459e35e1d5b97161a363/src/PostgREST/App.hs#L148-L166
  • Doing the above would require a series of refactors.
@steve-chavez
Copy link
Member Author

Log all generated queries for log-query = full.

Thinking more about this, to be really full we would need to also log the Schema cache queries at startup. That would need a similar treatment of "purifying" our SQL generation from Hasql too, I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants