diff --git a/fang/Cargo.toml b/fang/Cargo.toml index 5d8bc10..97be165 100644 --- a/fang/Cargo.toml +++ b/fang/Cargo.toml @@ -26,10 +26,10 @@ blocking = ["dep:diesel", "dep:diesel-derive-enum", "dep:dotenvy", "diesel?/chro blocking-postgres = [ "blocking", "diesel?/postgres"] blocking-sqlite = ["blocking", "diesel?/sqlite" ] blocking-mysql = [ "blocking", "diesel?/mysql"] -migrations-postgres = ["migrations"] -migrations-sqlite = ["migrations"] -migrations-mysql = ["migrations"] -migrations = ["dep:diesel_migrations"] +migrations-postgres = ["migrations", "diesel?/postgres"] +migrations-sqlite = ["migrations", "diesel?/sqlite"] +migrations-mysql = ["migrations", "diesel?/mysql"] +migrations = ["dep:diesel_migrations", "dep:diesel"] [dev-dependencies] diff --git a/fang/src/asynk.rs b/fang/src/asynk.rs index 2a8ab87..58d8fcf 100644 --- a/fang/src/asynk.rs +++ b/fang/src/asynk.rs @@ -1,10 +1,20 @@ +// Here you should put all the backends based on sqlx library +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] +pub mod backend_sqlx; + pub mod async_queue; pub mod async_runnable; pub mod async_worker; pub mod async_worker_pool; -pub mod backend_sqlx; -pub use async_queue::*; -pub use async_runnable::AsyncRunnable; -pub use async_worker::*; -pub use async_worker_pool::*; +// Here you should put all the backends. +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] +pub use {async_queue::*, async_runnable::AsyncRunnable, async_worker::*, async_worker_pool::*}; diff --git a/fang/src/asynk/backend_sqlx.rs b/fang/src/asynk/backend_sqlx.rs index 4093ed1..cfe57bb 100644 --- a/fang/src/asynk/backend_sqlx.rs +++ b/fang/src/asynk/backend_sqlx.rs @@ -1,15 +1,11 @@ -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Utc}; use sha2::Digest; use sha2::Sha256; -use sqlx::any::AnyQueryResult; -use sqlx::database::HasArguments; -use sqlx::Database; -use sqlx::Encode; -use sqlx::Executor; -use sqlx::FromRow; -use sqlx::IntoArguments; -use sqlx::Pool; -use sqlx::Type; +use { + chrono::Duration, sqlx::any::AnyQueryResult, sqlx::database::HasArguments, sqlx::Database, + sqlx::Encode, sqlx::Executor, sqlx::FromRow, sqlx::IntoArguments, sqlx::Pool, sqlx::Type, +}; + use std::fmt::Debug; use typed_builder::TypedBuilder; use uuid::Uuid; @@ -40,7 +36,6 @@ pub(crate) enum BackendSqlX { MySql, } -#[allow(dead_code)] #[derive(TypedBuilder, Clone)] pub(crate) struct QueryParams<'a> { #[builder(default, setter(strip_option))] @@ -63,7 +58,6 @@ pub(crate) struct QueryParams<'a> { task: Option<&'a Task>, } -#[allow(dead_code)] pub(crate) enum Res { Bigint(u64), Task(Task), @@ -143,7 +137,6 @@ use crate::FangTaskState; use crate::InternalPool; use crate::Task; -#[allow(dead_code)] pub(crate) fn calculate_hash(json: &str) -> String { let mut hasher = Sha256::new(); hasher.update(json.as_bytes()); diff --git a/fang/src/lib.rs b/fang/src/lib.rs index 7c1d009..f50abe7 100644 --- a/fang/src/lib.rs +++ b/fang/src/lib.rs @@ -149,7 +149,7 @@ impl From for &str { #[derive(Debug, Eq, PartialEq, Clone, TypedBuilder)] #[cfg_attr(feature = "blocking", derive(Queryable, Identifiable))] -#[diesel(table_name = fang_tasks)] +#[cfg_attr(feature = "blocking", diesel(table_name = fang_tasks))] pub struct Task { #[builder(setter(into))] pub id: Uuid, @@ -204,9 +204,18 @@ pub mod blocking; #[cfg(feature = "blocking")] pub use blocking::*; -#[cfg(feature = "asynk")] +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] pub mod asynk; +#[cfg(any( + feature = "asynk-postgres", + feature = "asynk-mysql", + feature = "asynk-sqlite" +))] #[cfg(feature = "asynk")] pub use asynk::*; @@ -218,10 +227,10 @@ pub use async_trait::async_trait; pub use fang_derive_error::ToFangError; #[cfg(feature = "migrations")] -use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; - -#[cfg(feature = "migrations")] -use std::error::Error as SomeError; +use { + diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}, + std::error::Error as SomeError, +}; #[cfg(feature = "migrations-postgres")] use diesel::pg::Pg;