Skip to content

feat: Use query_typed and variants#305

Draft
Destructor17 wants to merge 2 commits into
cornucopia-rs:mainfrom
webrogue-runtime:typed_query
Draft

feat: Use query_typed and variants#305
Destructor17 wants to merge 2 commits into
cornucopia-rs:mainfrom
webrogue-runtime:typed_query

Conversation

@Destructor17
Copy link
Copy Markdown

@Destructor17 Destructor17 commented May 20, 2026

Closes #283

As described in rust-postgres/rust-postgres#1147, only query_typed and variants are usable with some connection pools because non-typed query prepares statements just to obtain param types.

This PR uses query_typed if prepared statements are not needed. Such scenario is common for serverless apps. For example code generated by this fork works well with Cloudflare Hyperdrive.

Yeah also it should improve performance a bit if prepared statements are not used

However there are a few things that need to be discussed:

  • postgres_types::Type is surprisingly rich. How do we express it during codegen? I covered some simple types but that's not enough. Maybe there is some way to serialize it? Or, maybe we should fall back to non-typed query if a type can't be expressed?
  • If non-typed query fallback will not be used, non-typed params can also be removed.
  • I guess more tests should be added because 'postgres_types::Type' can't be tested at compile time and wrong type will cause runtime errors
  • Is it intentional that clorinde::client::async_::raw uses that IntoIterator for params instead of a simple slice like clorinde::client::async_::one? I have not managed to use IntoIterator for typed_params because it makes futures non-Send (I believe it also should be tested), while slices work just nice
  • Do src/codegen/client.rs becomes too bloated? I just added typed variant for almost every method of every client implementation and trait - lots of code that may be generated using some # magic in quote! instead of repeating things

How has this been tested?

I have not ran tests or benchmarks yet, and have not tried to generate sync code, but this seem to work.

At the time of writing this PR is a draft

The following has been done

  • PR title is prefixed with feat:, fix:, chore:, or docs:
  • The message body above clearly illustrates what problems it solves
  • If this PR has changed code within src, codegen for the repo has been run with cargo run --package test_integration -- --apply-codegen

Tests and linting

  • Formatting has been run with cargo fmt
  • Tests and lints have been run with cargo test --all and cargo clippy

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support database connections where prepared statements are unsupported

1 participant