Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
sfackler merged 2 commits intorust-postgres:masterfromNAlexPear:encode_format_types
Aug 16, 2022

Conversation

NAlexPear
Copy link
Contributor

#836 has been helpful as a way of pairing parameter types with their encodings, but theencode_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 timebind() 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.

let(param_formats, params):(Vec<_>,Vec<_>) = params
.into_iter()
.map(|p|(p.borrow_to_sql().encode_format()asi16, p))
.zip(param_types.iter())
Copy link
Collaborator

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.

Copy link
ContributorAuthor

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?

Copy link
Collaborator

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.

NAlexPear reacted with thumbs up emoji
Copy link
ContributorAuthor

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
Copy link
Collaborator

sfackler commentedAug 16, 2022
edited
Loading

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

NAlexPear reacted with thumbs up emoji

@sfacklersfackler merged commit91b2187 intorust-postgres:masterAug 16, 2022
@NAlexPearNAlexPear deleted the encode_format_types branchAugust 16, 2022 13:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sfacklersfacklersfackler left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@NAlexPear@sfackler

[8]ページ先頭

©2009-2025 Movatter.jp