sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.44k stars 436 forks source link

Encode Format based on Type #937

Closed NAlexPear closed 2 years ago

NAlexPear commented 2 years ago

836 has been helpful as a way of pairing parameter types with their encodings, but the encode_format method in the ToSql trait would be even more useful with the addition of a reference to Type. This would enable more granular encoding of parameters based on the types inferred by Postgres during the prepare 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 a Type parameter to the encode_format method added to ToSql, which should not be a breaking change if it can be made before the next release.

sfackler commented 2 years ago

I think you just need to rebase to fix the clippy error. LGTM otherwise!