From 56e35f4e65ed57c28b6c5a6a5f62a5bd9092bc66 Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Sat, 14 Sep 2024 14:06:33 -0400 Subject: [PATCH 1/5] start, upgrade sqlx to v0.8, includes fix for RUSTSEC-2024-0363 --- compact_str/Cargo.toml | 2 +- compact_str/src/features/sqlx.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compact_str/Cargo.toml b/compact_str/Cargo.toml index beed3998..2d67d760 100644 --- a/compact_str/Cargo.toml +++ b/compact_str/Cargo.toml @@ -41,7 +41,7 @@ quickcheck = { version = "1", optional = true, default-features = false } rkyv = { version = "0.7", optional = true, default-features = false, features = ["size_32"] } serde = { version = "1", optional = true, default-features = false, features = ["derive", "alloc"] } smallvec = { version = "1", optional = true, features = ["union"] } -sqlx = { version = "0.7", optional = true, default-features = false } +sqlx = { version = "0.8", optional = true, default-features = false } castaway = { version = "0.2.3", default-features = false, features = ["alloc"] } cfg-if = "1" diff --git a/compact_str/src/features/sqlx.rs b/compact_str/src/features/sqlx.rs index 314f118f..ac272f4b 100644 --- a/compact_str/src/features/sqlx.rs +++ b/compact_str/src/features/sqlx.rs @@ -5,7 +5,7 @@ use sqlx::error::BoxDynError; feature = "sqlx-postgres", feature = "sqlx-sqlite" ))] -use sqlx::{database::HasArguments, encode::IsNull, Encode}; +use sqlx::{encode::IsNull, Encode}; use sqlx::{Database, Decode, Type, Value, ValueRef}; use crate::{CompactString, ToCompactString}; From 3ffd450de69e6f9941dcae985a2e5bf761a0d0e0 Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Sat, 14 Sep 2024 14:11:34 -0400 Subject: [PATCH 2/5] updates to fix breaking changes --- compact_str/src/features/sqlx.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/compact_str/src/features/sqlx.rs b/compact_str/src/features/sqlx.rs index ac272f4b..da607701 100644 --- a/compact_str/src/features/sqlx.rs +++ b/compact_str/src/features/sqlx.rs @@ -1,4 +1,3 @@ -use sqlx::database::HasValueRef; use sqlx::error::BoxDynError; #[cfg(any( feature = "sqlx-mysql", @@ -28,7 +27,7 @@ where DB: Database, for<'x> &'x str: Decode<'x, DB> + Type, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let value = value.to_owned(); let value: &str = value.try_decode()?; Ok(value.try_to_compact_string()?) @@ -38,7 +37,10 @@ where #[cfg(feature = "sqlx-mysql")] #[cfg_attr(docsrs, doc(cfg(feature = "sqlx-mysql")))] impl<'q> Encode<'q, sqlx::MySql> for CompactString { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'q>, + ) -> Result { Encode::<'_, sqlx::MySql>::encode_by_ref(&self.as_str(), buf) } @@ -58,8 +60,8 @@ impl<'q> Encode<'q, sqlx::MySql> for CompactString { impl<'q> Encode<'q, sqlx::Postgres> for CompactString { fn encode_by_ref( &self, - buf: &mut >::ArgumentBuffer, - ) -> IsNull { + buf: &mut ::ArgumentBuffer<'q>, + ) -> Result { Encode::<'_, sqlx::Postgres>::encode_by_ref(&self.as_str(), buf) } @@ -85,14 +87,17 @@ impl sqlx::postgres::PgHasArrayType for CompactString { #[cfg(feature = "sqlx-sqlite")] #[cfg_attr(docsrs, doc(cfg(feature = "sqlx-sqlite")))] impl<'q> Encode<'q, sqlx::Sqlite> for CompactString { - fn encode(self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode( + self, + buf: &mut ::ArgumentBuffer<'q>, + ) -> Result { Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf) } fn encode_by_ref( &self, - buf: &mut >::ArgumentBuffer, - ) -> IsNull { + buf: &mut ::ArgumentBuffer<'q>, + ) -> Result { Encode::<'_, sqlx::Sqlite>::encode(alloc::string::String::from(self.as_str()), buf) } From 9f498c22d3dea6c06bb4e5ea125d377498527c5a Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Sat, 14 Sep 2024 14:16:10 -0400 Subject: [PATCH 3/5] update sqlx dep in example --- examples/sqlx/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sqlx/Cargo.toml b/examples/sqlx/Cargo.toml index 0399e391..eb1fe835 100644 --- a/examples/sqlx/Cargo.toml +++ b/examples/sqlx/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" [dependencies] compact_str = { version = "0.8.0-beta", path = "../../compact_str", features = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"] } -sqlx = { version = "0.7", features = ["runtime-tokio", "mysql", "postgres", "sqlite"] } +sqlx = { version = "0.8", features = ["runtime-tokio", "mysql", "postgres", "sqlite"] } tempfile = "3" tokio = { version = "1.20.0", features = ["rt", "macros"]} From 4bad7c2bd0bd865a5e9c2674ad4be337019e231a Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Sun, 29 Dec 2024 15:25:20 -0500 Subject: [PATCH 4/5] a few fixes * skip using to_owned in impl of Decode, defer to Decode impl for &str * fix clippy in sqlx example --- compact_str/src/features/sqlx.rs | 5 ++--- examples/sqlx/src/lib.rs | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compact_str/src/features/sqlx.rs b/compact_str/src/features/sqlx.rs index da607701..66f64ea4 100644 --- a/compact_str/src/features/sqlx.rs +++ b/compact_str/src/features/sqlx.rs @@ -5,7 +5,7 @@ use sqlx::error::BoxDynError; feature = "sqlx-sqlite" ))] use sqlx::{encode::IsNull, Encode}; -use sqlx::{Database, Decode, Type, Value, ValueRef}; +use sqlx::{Database, Decode, Type}; use crate::{CompactString, ToCompactString}; @@ -28,8 +28,7 @@ where for<'x> &'x str: Decode<'x, DB> + Type, { fn decode(value: ::ValueRef<'r>) -> Result { - let value = value.to_owned(); - let value: &str = value.try_decode()?; + let value = <&str as Decode>::decode(value)?; Ok(value.try_to_compact_string()?) } } diff --git a/examples/sqlx/src/lib.rs b/examples/sqlx/src/lib.rs index c4f6a5fd..78d28713 100644 --- a/examples/sqlx/src/lib.rs +++ b/examples/sqlx/src/lib.rs @@ -41,8 +41,8 @@ macro_rules! test_body { // insert a new todo let mut transaction = conn.begin().await?; let mut args = <$DbArguments>::default(); - args.add(TITLE); - args.add(false); + args.add(TITLE).unwrap(); + args.add(false).unwrap(); let q = query_with("INSERT INTO todos (title, done) VALUES ($1, $2)", args); transaction.execute(q).await?; transaction.commit().await?; @@ -68,8 +68,8 @@ macro_rules! test_body { let mut transaction = conn.begin().await?; println!("Hello!"); let mut args = <$DbArguments>::default(); - args.add(true); - args.add(id); + args.add(true).unwrap(); + args.add(id).unwrap(); let q = query_with("UPDATE todos SET done = $1 WHERE id = $2", args); transaction.execute(q).await?; transaction.commit().await?; @@ -94,7 +94,7 @@ macro_rules! test_body { // we are done, delete our todo let mut transaction = conn.begin().await?; let mut args = <$DbArguments>::default(); - args.add(TITLE); + args.add(TITLE).unwrap(); let q = query_with("DELETE FROM todos WHERE title = $1", args); transaction.execute(q).await?; transaction.commit().await?; From ffd9abab26ec0449a1a2ad0329c6ed979e302c9d Mon Sep 17 00:00:00 2001 From: Parker Timmerman Date: Sun, 29 Dec 2024 15:30:37 -0500 Subject: [PATCH 5/5] fix CI --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40424d7d..06c0fcba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,8 +34,8 @@ jobs: fail-fast: false matrix: include: - - toolchain: ${{ env.RUST_VERSION }} - - toolchain: ${{ env.RUST_NIGHTLY_VERSION }} + - toolchain: "1.83.0" + - toolchain: "nightly-2024-12-20" name: cargo test runs-on: ubuntu-latest @@ -64,8 +64,8 @@ jobs: - name: Install toolchain run: | - rustup toolchain install ${{ env.RUST_NIGHTLYVERSION }} --no-self-update --profile minimal --component miri - rustup override set ${{ env.RUST_NIGHTLYVERSION }} + rustup toolchain install ${{ env.RUST_NIGHTLY_VERSION }} --no-self-update --profile minimal --component miri + rustup override set ${{ env.RUST_NIGHTLY_VERSION }} - name: Install cargo-nextest uses: taiki-e/install-action@nextest - uses: Swatinem/rust-cache@v2 @@ -85,8 +85,8 @@ jobs: - name: Install toolchain run: | - rustup toolchain install ${{ env.RUST_NIGHTLYVERSION }} --no-self-update --profile minimal - rustup override set ${{ env.RUST_NIGHTLYVERSION }} + rustup toolchain install ${{ env.RUST_NIGHTLY_VERSION }} --no-self-update --profile minimal + rustup override set ${{ env.RUST_NIGHTLY_VERSION }} - name: Install cargo-nextest uses: taiki-e/install-action@nextest - uses: Swatinem/rust-cache@v2