feat: support borrowed parameter types via borrowed_rs_type override#19
Merged
Conversation
Adds a `borrowed_rs_type` field to type overrides so callers can take parameters by reference without forcing rows to also be borrowed. When set, the override participates in borrowed mode for scalar parameter positions; rows, array contents, and copyfrom items continue to use the owned form. Lifetimes are threaded via elision wherever possible: single-param functions take the borrowed type directly; params structs gain `<'a>` with the fn referencing it as `<'_>`; batch streams reuse the existing `'a`; copyfrom introduces `'a` because its where clause cannot elide. Vec wrappers around borrowed inners become `&[T_owned]` so a caller holding a `Vec<String>` can pass `&v` without re-collecting. `rs_type` becomes optional when `borrowed_rs_type` is present; `borrowed_rs_type` is parsed at config load and rejected if it does not contain a reference, so a value like `Option<String>` fails fast.
jrandolf
added a commit
that referenced
this pull request
May 18, 2026
🤖 I have created a release *beep* *boop* --- ## [0.2.1](v0.2.0...v0.2.1) (2026-05-18) ### Features * Support borrowed parameter types via borrowed_rs_type override ([#19](#19)) ([6ce89a3](6ce89a3)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
borrowed_rs_typeto type overrides — scalar params take the borrowed form while rows, array contents, and:copyfromitems keep the owned form.<'a>with the fn ref using<'_>; batch streams reuse the existing'a;:copyfromintroduces'abecause itswhere Item = ...clause cannot elide.Vec<T>wrappers around borrowed inners become&[T_owned]so a caller holding aVec<String>can pass&vdirectly.rs_typebecomes optional alongsideborrowed_rs_type; the borrowed value is validated at config load and rejected if it does not contain a reference (e.g.Option<String>fails fast).examples/borrowed/and a "Borrowed parameters" section in the README.Test plan
cargo test --lib -p sqlc-gen-sqlx— 88 unit tests passcargo test --test codegen -p sqlc-gen-sqlx— 30 codegen tests pass (9 new snapshots: scalar, struct, nullable, array, slice, batch single/struct, copyfrom, owned+borrowed pair, row-unaffected)cargo clippy --workspace --all-targets -- -D warningscleancargo fmt --all --checkcleanmise run generateproduces the borrowed example's checked-inqueries.rsbyte-identicallycargo test -p borrowedpasses end-to-end against a local Postgres (INSERT with&strliterals, SELECT with&String, owned row fields round-trip)