diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07c2f7c..e97462b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: include: - - { rust: stable, os: ubuntu-22.04 } + - { rust: stable, os: ubuntu-24.04 } services: clickhouse: image: clickhouse/clickhouse-server:25.8.4 @@ -28,7 +28,7 @@ jobs: --ulimit nofile=262144:262144 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} @@ -49,7 +49,7 @@ jobs: fail-fast: false matrix: include: - - { rust: 1.75.0, os: ubuntu-22.04 } + - { rust: 1.85.0, os: ubuntu-24.04 } services: clickhouse: image: clickhouse/clickhouse-server:25.8.4 @@ -61,7 +61,7 @@ jobs: --ulimit nofile=262144:262144 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -84,10 +84,10 @@ jobs: fail-fast: false matrix: include: - - { rust: nightly-2024-03-31, os: ubuntu-22.04 } + - { rust: nightly-2026-03-10, os: ubuntu-24.04 } steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -108,10 +108,10 @@ jobs: fail-fast: false matrix: include: - - { rust: stable, os: ubuntu-22.04 } + - { rust: stable, os: ubuntu-24.04 } steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -129,10 +129,10 @@ jobs: # fail-fast: false # matrix: # include: - # - { rust: stable, os: ubuntu-22.04 } + # - { rust: stable, os: ubuntu-24.04 } # steps: # - name: Checkout - # uses: actions/checkout@v4 + # uses: actions/checkout@v6 # with: # submodules: true # - uses: dtolnay/rust-toolchain@stable diff --git a/klickhouse/Cargo.toml b/klickhouse/Cargo.toml index c864003..da67136 100644 --- a/klickhouse/Cargo.toml +++ b/klickhouse/Cargo.toml @@ -2,14 +2,14 @@ name = "klickhouse" version = "0.14.0" authors = ["Protryon "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/Protryon/klickhouse" description = "Klickhouse is a pure Rust SDK for working with Clickhouse with the native protocol in async environments with minimal boilerplate and maximal performance." keywords = ["clickhouse", "database", "tokio", "sql"] readme = "../README.md" autotests = false -rust-version = "1.75.0" +rust-version = "1.85.0" [package.metadata.docs.rs] all-features = true diff --git a/klickhouse/examples/basic.rs b/klickhouse/examples/basic.rs index 43e29b3..b2b18d1 100644 --- a/klickhouse/examples/basic.rs +++ b/klickhouse/examples/basic.rs @@ -1,6 +1,7 @@ use chrono::Utc; use futures_util::StreamExt; use klickhouse::*; +use tokio::sync::oneshot; #[derive(Row, Debug, Default)] pub struct MyUserData { @@ -18,25 +19,38 @@ async fn main() { .await .unwrap(); + let (tx, mut rx) = oneshot::channel::<()>(); + // Retrieve and display query progress events let mut progress = client.subscribe_progress(); let progress_task = tokio::task::spawn(async move { let mut current_query = Uuid::nil(); let mut progress_total = Progress::default(); - while let Ok((query, progress)) = progress.recv().await { - if query != current_query { - progress_total = Progress::default(); - current_query = query; + + loop { + tokio::select! { + // Stop task + _ = &mut rx => { + break + } + + // Progress loop + Ok((query, progress)) = progress.recv() => { + if query != current_query { + progress_total = Progress::default(); + current_query = query; + } + progress_total += progress; + println!( + "Progress on query {}: {}/{} {:.2}%", + query, + progress_total.read_rows, + progress_total.new_total_rows_to_read, + 100.0 * progress_total.read_rows as f64 + / progress_total.new_total_rows_to_read as f64 + ); + } } - progress_total += progress; - println!( - "Progress on query {}: {}/{} {:.2}%", - query, - progress_total.read_rows, - progress_total.new_total_rows_to_read, - 100.0 * progress_total.read_rows as f64 - / progress_total.new_total_rows_to_read as f64 - ); } }); @@ -81,7 +95,7 @@ async fn main() { println!("row received '{}': {:?}", row.id, row); } - // Drop the client so that the progress task finishes. - drop(client); + // Send signal so that the progress task finishes. + tx.send(()).unwrap(); progress_task.await.unwrap(); } diff --git a/klickhouse/examples/pool.rs b/klickhouse/examples/pool.rs index f60a9e7..6973f72 100644 --- a/klickhouse/examples/pool.rs +++ b/klickhouse/examples/pool.rs @@ -1,6 +1,7 @@ use chrono::Utc; use futures_util::StreamExt; use klickhouse::*; +use tokio::sync::oneshot; #[derive(Row, Debug, Default)] pub struct MyUserData { @@ -26,25 +27,38 @@ async fn main() { let client = pool.get().await.unwrap(); + let (tx, mut rx) = oneshot::channel::<()>(); + // Retrieve and display query progress events let mut progress = client.subscribe_progress(); let progress_task = tokio::task::spawn(async move { let mut current_query = Uuid::nil(); let mut progress_total = Progress::default(); - while let Ok((query, progress)) = progress.recv().await { - if query != current_query { - progress_total = Progress::default(); - current_query = query; + + loop { + tokio::select! { + // Stop task + _ = &mut rx => { + break + } + + // Progress loop + Ok((query, progress)) = progress.recv() => { + if query != current_query { + progress_total = Progress::default(); + current_query = query; + } + progress_total += progress; + println!( + "Progress on query {}: {}/{} {:.2}%", + query, + progress_total.read_rows, + progress_total.new_total_rows_to_read, + 100.0 * progress_total.read_rows as f64 + / progress_total.new_total_rows_to_read as f64 + ); + } } - progress_total += progress; - println!( - "Progress on query {}: {}/{} {:.2}%", - query, - progress_total.read_rows, - progress_total.new_total_rows_to_read, - 100.0 * progress_total.read_rows as f64 - / progress_total.new_total_rows_to_read as f64 - ); } }); @@ -89,7 +103,7 @@ async fn main() { println!("row received '{}': {:?}", row.id, row); } - // Drop the client so that the progress task finishes. - drop(client); + // Send signal so that the progress task finishes. + tx.send(()).unwrap(); progress_task.await.unwrap(); } diff --git a/klickhouse/rustfmt.toml b/klickhouse/rustfmt.toml index 3a26366..f216078 100644 --- a/klickhouse/rustfmt.toml +++ b/klickhouse/rustfmt.toml @@ -1 +1 @@ -edition = "2021" +edition = "2024" diff --git a/klickhouse/src/convert/std_deserialize.rs b/klickhouse/src/convert/std_deserialize.rs index c0f8858..3da173e 100644 --- a/klickhouse/src/convert/std_deserialize.rs +++ b/klickhouse/src/convert/std_deserialize.rs @@ -328,7 +328,7 @@ impl FromSql for Box { } macro_rules! tuple_impls { - ($($len:expr => ($($n:tt $name:ident)+))+) => { + ($($len:literal => ($($n:tt $name:ident)+))+) => { $( impl<$($name: FromSql),+> FromSql for ($($name,)+) { fn from_sql(type_: &Type, value: Value) -> Result { diff --git a/klickhouse/src/convert/std_serialize.rs b/klickhouse/src/convert/std_serialize.rs index e481871..ac435e6 100644 --- a/klickhouse/src/convert/std_serialize.rs +++ b/klickhouse/src/convert/std_serialize.rs @@ -209,7 +209,7 @@ impl ToSql for Box { } macro_rules! tuple_impls { - ($($len:expr => ($($n:tt $name:ident)+))+) => { + ($($len:literal => ($($n:tt $name:ident)+))+) => { $( impl<$($name: ToSql),+> ToSql for ($($name,)+) { fn to_sql(self, type_hint: Option<&Type>) -> Result { diff --git a/klickhouse_derive/Cargo.toml b/klickhouse_derive/Cargo.toml index 1556c1e..f44565b 100644 --- a/klickhouse_derive/Cargo.toml +++ b/klickhouse_derive/Cargo.toml @@ -2,12 +2,12 @@ name = "klickhouse_derive" version = "0.13.0" authors = ["Protryon "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/Protryon/klickhouse" description = "proc-macro crate for klickhouse" keywords = [ "clickhouse", "database", "tokio", "sql" ] -rust-version = "1.75.0" +rust-version = "1.85.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html