Add better ParsedQuery semantics around client APIs#101
Open
Qix- wants to merge 1 commit into
Open
Conversation
Qix-
commented
Jun 3, 2026
Comment on lines
+83
to
+88
| .query::<MyUserData>( | ||
| QueryBuilder::new("SELECT * FROM klickhouse_example WHERE 1=?;") | ||
| .arg(1) | ||
| .finalize() | ||
| .unwrap(), | ||
| ) |
Author
There was a problem hiding this comment.
Happy to revert this back to the original; I just wanted a reproduction test case that I was facing in my own application that prompted this PR in the first place. This invocation won't compile on the current HEAD.
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.
Right now passing a
ParsedQueryverbatim into the client query methods causes a compilation error. SinceTryInto<ParsedQuery> for ParsedQueryis an identity, the blanket implementation by the Rust language namestype Error = core::convert::Infallible.Therefore, there needed to be a way to specify that as long as the error message could be coerced into a
KlickhouseError, that that was sufficient for the client library to work. I started by doingBut that caused some (already) awkward semantics around
query()(anduse<>, a new thing from Edition 2024, that forces the use of explicit generic parameters) to get even worse (requiring.query()without an implicit return type to be spelled.query::<SomeRowType, _, _>(...)for all invocations).Therefore I pulled out the explicit
TryIntoargument types into their own traitTryIntoQueryto drastically clean up the code and error handling (primarily around.query()), which didn't yet get rid of the captured lifetimes issue as I had hoped.Took some finagling but I realized that the
use<>could be removed ifRowwas marked'static, which is really what the error was complaining about. I would be... surprised (perhaps concerned) if a typicalRowis a non-static item being serialized/deserialized from Klickhouse, and given that it's almost always being implemented by the derives, I would imagine this is a fair tradeoff.Now not only can you pass the already-unwrapped results of parsed queries into the client methods directly without hitting the
KlickhouseError == Infalliblecompilation error, but now.query::<T>()doesn't need to have the extra, _>at the end of each invocation.