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 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..66f64ea4 100644 --- a/compact_str/src/features/sqlx.rs +++ b/compact_str/src/features/sqlx.rs @@ -1,12 +1,11 @@ -use sqlx::database::HasValueRef; use sqlx::error::BoxDynError; #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-postgres", feature = "sqlx-sqlite" ))] -use sqlx::{database::HasArguments, encode::IsNull, Encode}; -use sqlx::{Database, Decode, Type, Value, ValueRef}; +use sqlx::{encode::IsNull, Encode}; +use sqlx::{Database, Decode, Type}; use crate::{CompactString, ToCompactString}; @@ -28,9 +27,8 @@ where DB: Database, for<'x> &'x str: Decode<'x, DB> + Type, { - fn decode(value: >::ValueRef) -> Result { - let value = value.to_owned(); - let value: &str = value.try_decode()?; + fn decode(value: ::ValueRef<'r>) -> Result { + let value = <&str as Decode>::decode(value)?; Ok(value.try_to_compact_string()?) } } @@ -38,7 +36,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 +59,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 +86,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) } 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"]} 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?;