-
Notifications
You must be signed in to change notification settings - Fork 134
Implement query with interpolation flags #259
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ozgurcancal
wants to merge
1
commit into
ClickHouse:main
Choose a base branch
from
ozgurcancal:query_flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Suppress Clippy warning due to identical names for the folder and file (`query`) | ||
#![allow(clippy::module_inception)] | ||
|
||
// Declare the submodules | ||
mod query; | ||
mod query_flags; | ||
|
||
// Re-export public items | ||
pub use crate::cursors::{BytesCursor, RowCursor}; | ||
pub use query::Query; | ||
pub use query_flags::QI; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Query interpolation flags for controlling SQL template processing. | ||
/// | ||
/// This struct provides compile-time constants that control how SQL templates | ||
/// are processed, specifically for `?` parameter binding and `?fields` substitution. | ||
#[derive(Clone)] | ||
pub struct QI; | ||
|
||
impl QI { | ||
/// No interpolation features enabled. `?` becomes `NULL`, `?fields` is skipped. Implemented only for test purposes | ||
pub const NONE: u8 = 0; | ||
|
||
/// Enable `?fields` substitution with struct field names. | ||
pub const FIELDS: u8 = 0b0001; | ||
|
||
/// Enable `?` parameter binding with `.bind()` method. | ||
pub const BIND: u8 = 0b0010; | ||
|
||
/// Default flags used by `.query()` method. | ||
/// | ||
/// By default, only `?fields` substitution is enabled. Parameter binding (`?`) | ||
/// is opt-in via `Client::query_with_flags`. | ||
pub const DEFAULT: u8 = QI::FIELDS; | ||
|
||
/// All interpolation features enabled. | ||
pub const ALL: u8 = QI::FIELDS | QI::BIND; | ||
|
||
/// Compile-time flag checking functions | ||
#[inline(always)] | ||
pub const fn has_fields(flags: u8) -> bool { | ||
(flags & Self::FIELDS) != 0 | ||
} | ||
|
||
#[inline(always)] | ||
pub const fn has_bind(flags: u8) -> bool { | ||
(flags & Self::BIND) != 0 | ||
} | ||
} |
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
Oops, something went wrong.
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.
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.
Changing a public type should be a major version bump.
Can this be avoided, by the way? What is the purpose of having
INTERPFLAGS
here instead of a regular setter?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.
Thanks for your comment. I think discouraging unconscious use of bind or fields function should be query wise. Otherwise, it would appear less intuitive and introduce unnecessary complexity, since these functions are commonly used with both execute and fetch.
Therefore, handling interpolation only in fetch would not be sufficient. If fetch were the only place where interpolation was needed, I would simply enable all flags (including bind and fields) and update the interpolation state directly via the fetch function template argument.