From 814608e1e704ecbb261669c4250ceb557e591843 Mon Sep 17 00:00:00 2001 From: Serhii Temchenko Date: Mon, 25 Nov 2024 13:55:43 -0800 Subject: [PATCH 1/4] Exposed method to control read only query parameter --- src/query.rs | 19 ++++++++++++++----- src/watch.rs | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/query.rs b/src/query.rs index eba1915..df8e58f 100644 --- a/src/query.rs +++ b/src/query.rs @@ -22,6 +22,7 @@ pub use crate::cursor::RowCursor; pub struct Query { client: Client, sql: SqlBuilder, + is_read_only: bool, } impl Query { @@ -29,6 +30,7 @@ impl Query { Self { client: client.clone(), sql: SqlBuilder::new(template), + is_read_only: true, } } @@ -58,7 +60,7 @@ impl Query { /// Executes the query. pub async fn execute(self) -> Result<()> { - self.do_execute(false)?.finish().await + self.read_only(false).do_execute()?.finish().await } /// Executes the query, returning a [`RowCursor`] to obtain results. @@ -86,7 +88,7 @@ impl Query { self.sql.bind_fields::(); self.sql.append(" FORMAT RowBinary"); - let response = self.do_execute(true)?; + let response = self.do_execute()?; Ok(RowCursor::new(response)) } @@ -132,7 +134,14 @@ impl Query { Ok(result) } - pub(crate) fn do_execute(self, read_only: bool) -> Result { + /// Sets the read only option. + pub fn read_only(mut self, is_read_only: bool) -> Self { + self.is_read_only = is_read_only; + + self + } + + pub(crate) fn do_execute(self) -> Result { let query = self.sql.finish()?; let mut url = @@ -144,10 +153,10 @@ impl Query { pairs.append_pair("database", database); } - let use_post = !read_only || query.len() > MAX_QUERY_LEN_TO_USE_GET; + let use_post = !self.is_read_only || query.len() > MAX_QUERY_LEN_TO_USE_GET; let (method, body, content_length) = if use_post { - if read_only { + if self.is_read_only { pairs.append_pair("readonly", "1"); } let len = query.len(); diff --git a/src/watch.rs b/src/watch.rs index 1914399..7ee180f 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -254,7 +254,7 @@ async fn init_cursor(client: &Client, params: &WatchParams) -> Result Date: Mon, 25 Nov 2024 15:57:33 -0800 Subject: [PATCH 2/4] Updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8511848..6b1f1a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,12 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - query/cursor: improve performance of `RowCursor::next()` ([#169]). +- exposed method to control the `readonly` query parameter ([#181]). ### Fixed - mock: work with the advanced time via `tokio::time::advance()` ([#165]). [#165]: https://github.com/ClickHouse/clickhouse-rs/pull/165 [#169]: https://github.com/ClickHouse/clickhouse-rs/pull/169 +[#181]: https://github.com/ClickHouse/clickhouse-rs/pull/181 ## [0.13.0] - 2024-09-27 ### Added From d57ecceede813631de6f56d56ec8a9049025ed2a Mon Sep 17 00:00:00 2001 From: Serhii Temchenko Date: Mon, 25 Nov 2024 16:05:55 -0800 Subject: [PATCH 3/4] Removed hardcoded read only definition --- src/query.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query.rs b/src/query.rs index df8e58f..44ee23f 100644 --- a/src/query.rs +++ b/src/query.rs @@ -60,7 +60,7 @@ impl Query { /// Executes the query. pub async fn execute(self) -> Result<()> { - self.read_only(false).do_execute()?.finish().await + self.do_execute()?.finish().await } /// Executes the query, returning a [`RowCursor`] to obtain results. From e2c12b8ceca484d79f6fda357b9c40f97f50a955 Mon Sep 17 00:00:00 2001 From: Serhii Temchenko Date: Mon, 25 Nov 2024 16:07:51 -0800 Subject: [PATCH 4/4] Updated CHANGELOG.md with the topic entrance --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1f1a5..5c918fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - query/cursor: improve performance of `RowCursor::next()` ([#169]). -- exposed method to control the `readonly` query parameter ([#181]). +- query: exposed method to control the `readonly` query parameter ([#181]). ### Fixed - mock: work with the advanced time via `tokio::time::advance()` ([#165]).