Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compiling issue with diesel asynk #157

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::*};
19 changes: 6 additions & 13 deletions fang/src/asynk/backend_sqlx.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))]
Expand All @@ -63,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 @@ -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());
Expand Down
21 changes: 15 additions & 6 deletions fang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl From<FangTaskState> 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,
Expand Down 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
Loading