diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-31 13:43:20 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-31 13:43:20 -0500 |
commit | 1e3014a777805d3dcb691ee6ebe59c62f58f8222 (patch) | |
tree | 938d14db72c52dd96f5345fb084fd603c9dcebeb | |
parent | 88366acba07b678466b42829887dcdda4f583686 (diff) |
Remove sqlx dependency from webapp crate
-rw-r--r-- | protocol/Cargo.toml | 4 | ||||
-rw-r--r-- | protocol/src/card.rs | 22 | ||||
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/tests/db_test.rs | 2 |
4 files changed, 18 insertions, 12 deletions
diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index dc1510d..20de18b 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +db = ["dep:sqlx"] [dependencies] serde = { version = "1.0.145", features = ["derive"] } @@ -17,7 +19,7 @@ log = "0.4" regex = "1.0" lazy_static = "1.4" async-trait = "0.1.58" -sqlx = { version = "0.6", features = ["runtime-tokio-native-tls", "postgres", "uuid", "chrono", "json", "offline"] } +sqlx = { version = "0.6", features = ["runtime-tokio-native-tls", "postgres", "uuid", "chrono", "json", "offline"] , optional = true } [dev-dependencies] env_logger = "0.10.0" diff --git a/protocol/src/card.rs b/protocol/src/card.rs index 31d389a..b551a16 100644 --- a/protocol/src/card.rs +++ b/protocol/src/card.rs @@ -1,18 +1,17 @@ use anyhow::anyhow; pub(crate) use serde::{Deserialize, Serialize}; -use sqlx::encode::IsNull; -use sqlx::error::BoxDynError; -use sqlx::postgres::PgArgumentBuffer; -use sqlx::postgres::PgTypeInfo; -use sqlx::Postgres; -use sqlx::postgres::PgValueRef; -use strum_macros::FromRepr; +#[cfg(feature = "db")] +use sqlx::{ + encode::IsNull, error::BoxDynError, postgres::PgArgumentBuffer, + postgres::PgTypeInfo, postgres::PgValueRef, Postgres, +}; use std::fmt; use strum::EnumCount; use strum::IntoEnumIterator; use strum_macros::EnumCount; use strum_macros::EnumIter; +use strum_macros::FromRepr; #[derive( PartialOrd, @@ -78,19 +77,23 @@ impl fmt::Display for Suit { } } +#[cfg(feature = "db")] impl sqlx::Type<Postgres> for Rank { fn type_info() -> PgTypeInfo { <i16 as sqlx::Type<Postgres>>::type_info() } } +#[cfg(feature = "db")] impl sqlx::Decode<'_, Postgres> for Rank { fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> { let value = <i16 as sqlx::Decode<Postgres>>::decode(value)?; - Ok(Rank::from_repr(u8::try_from(value).expect("domain check")).expect("domain check")) + Ok(Rank::from_repr(u8::try_from(value).expect("domain check")) + .expect("domain check")) } } +#[cfg(feature = "db")] impl sqlx::Encode<'_, Postgres> for Rank { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull { let pg_value = *self as i16; @@ -98,12 +101,14 @@ impl sqlx::Encode<'_, Postgres> for Rank { } } +#[cfg(feature = "db")] impl sqlx::Type<Postgres> for Suit { fn type_info() -> PgTypeInfo { <&str as sqlx::Type<Postgres>>::type_info() } } +#[cfg(feature = "db")] impl sqlx::Decode<'_, Postgres> for Suit { fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> { let value = <&str as sqlx::Decode<Postgres>>::decode(value)?; @@ -117,6 +122,7 @@ impl sqlx::Decode<'_, Postgres> for Suit { } } +#[cfg(feature = "db")] impl sqlx::Encode<'_, Postgres> for Suit { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull { let pg_value = match *self { diff --git a/server/Cargo.toml b/server/Cargo.toml index 9062058..4db1891 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -14,7 +14,7 @@ tokio = { version = "1.21.2", features = ["full"] } tower-http = { version = "0.3.4", features = ["full"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -protocol = { path = "../protocol" } +protocol = { path = "../protocol", features = ["db"] } openidconnect = "2.3.2" lru = "0.8.1" uuid = { version = "1.1.2", features = ["serde", "fast-rng", "v4"] } diff --git a/server/tests/db_test.rs b/server/tests/db_test.rs index e495d78..f635ad5 100644 --- a/server/tests/db_test.rs +++ b/server/tests/db_test.rs @@ -1,6 +1,4 @@ use protocol::card::{Rank, Suit}; -use sqlx::Row; -use tracing::info; mod common; |