- Notifications
You must be signed in to change notification settings - Fork516
Encode Format based on Type#937
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
tokio-postgres/src/query.rs Outdated
let(param_formats, params):(Vec<_>,Vec<_>) = params | ||
.into_iter() | ||
.map(|p|(p.borrow_to_sql().encode_format()asi16, p)) | ||
.zip(param_types.iter()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
A zipped iterator stops as soon as the shortest iterator ends, so the length check below won't work properly. You may need to manually iterate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Would it be better (or sufficient) to move the length check before thezip
to guard against the early-ending case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Oh yeah, we already require ExactSizeIterator so we can just move the assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great, updatedin this commit.
sfackler commentedAug 16, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think you just need to rebase to fix the clippy error. LGTM otherwise! |
4e0aaee
to8158eed
Compare
#836 has been helpful as a way of pairing parameter types with their encodings, but the
encode_format
method in theToSql
trait would be even more useful with the addition of a reference toType
. This would enable more granular encoding of parameters based on the types inferred by Postgres during theprepare
phase, which would be useful when processing payloads from more general type systems like gRPC or JSON.Since parameter types are already generated by the time
bind()
is called, it's easy to include them as part of the format-generating process. This PR simply adds aType
parameter to theencode_format
method added toToSql
, which should not be a breaking change if it can be made before the next release.