Skip to content

Commit

Permalink
rework optional compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
pxp9 committed Oct 13, 2024
1 parent 2ddc4d1 commit 567bc39
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
8 changes: 4 additions & 4 deletions fang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 15 additions & 5 deletions fang/src/asynk.rs
Original file line number Diff line number Diff line change
@@ -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::*};
14 changes: 0 additions & 14 deletions fang/src/asynk/backend_sqlx.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use chrono::{DateTime, Utc};
use sha2::Digest;
use sha2::Sha256;

#[cfg(all(
feature = "asynk-postgres",
feature = "asynk-sqlite",
feature = "asynk-mysql"
))]
use {
chrono::Duration, sqlx::any::AnyQueryResult, sqlx::database::HasArguments, sqlx::Database,
sqlx::Encode, sqlx::Executor, sqlx::FromRow, sqlx::IntoArguments, sqlx::Pool, sqlx::Type,
Expand Down Expand Up @@ -42,7 +36,6 @@ pub(crate) enum BackendSqlX {
MySql,
}

#[allow(dead_code)]
#[derive(TypedBuilder, Clone)]
pub(crate) struct QueryParams<'a> {
#[builder(default, setter(strip_option))]
Expand All @@ -65,7 +58,6 @@ pub(crate) struct QueryParams<'a> {
task: Option<&'a Task>,
}

#[allow(dead_code)]
pub(crate) enum Res {
Bigint(u64),
Task(Task),
Expand Down Expand Up @@ -145,19 +137,13 @@ 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());
let result = hasher.finalize();
hex::encode(result)
}

#[cfg(all(
feature = "asynk-postgres",
feature = "asynk-sqlite",
feature = "asynk-mysql"
))]
trait FangQueryable<DB>
where
DB: Database,
Expand Down
19 changes: 14 additions & 5 deletions fang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -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;
Expand Down

0 comments on commit 567bc39

Please sign in to comment.