Skip to content

Commit

Permalink
make it work, with new without any warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pxp9 committed Dec 14, 2024
1 parent 009b61c commit 309e144
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
9 changes: 7 additions & 2 deletions fang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ diesel_migrations = { version = "2.1", features = [
# "mysql",
#] }

sqlx = { git = "https://github.com/pxp9/sqlx.git", branch = "main", features = [
sqlx = { git = "https://github.com/launchbadge/sqlx.git", branch = "main", features = [
"any",
"macros",
"chrono",
Expand All @@ -84,6 +84,9 @@ sqlx = { git = "https://github.com/pxp9/sqlx.git", branch = "main", features = [
"mysql",
] }

url = { version = "2.2.2" }


#console-subscriber = "0.2.0" # for tokio tracing debug

[dependencies]
Expand All @@ -100,7 +103,7 @@ typed-builder = "0.14"
typetag = "0.2"
uuid = { version = "1.1", features = ["v4"] }
fang-derive-error = { version = "0.1.0", optional = true }
sqlx = { git = "https://github.com/pxp9/sqlx.git", branch = "main", features = [
sqlx = { git = "https://github.com/launchbadge/sqlx.git", branch = "main", features = [
"any",
"macros",
"chrono",
Expand All @@ -109,6 +112,8 @@ sqlx = { git = "https://github.com/pxp9/sqlx.git", branch = "main", features = [
"runtime-tokio-rustls",
], optional = true }

url = { version = "2.2.2" }


[dependencies.diesel]
version = "2.1"
Expand Down
18 changes: 9 additions & 9 deletions fang/src/asynk/async_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ use chrono::DateTime;
use chrono::Utc;
use cron::Schedule;
use sqlx::any::install_default_drivers;
use sqlx::any::Any;
use sqlx::any::AnyTypeInfo;

#[cfg(any(
feature = "asynk-postgres",
feature = "asynk-mysql",
feature = "asynk-sqlite"
))]
use sqlx::pool::PoolOptions;
use sqlx::Encode;
use sqlx::TypeInfo;
use std::str::FromStr;
use thiserror::Error;
use typed_builder::TypedBuilder;
use url::Url;
use uuid::Uuid;

#[cfg(feature = "asynk-postgres")]
Expand Down Expand Up @@ -56,6 +54,8 @@ pub enum AsyncQueueError {
#[error(transparent)]
SerdeError(#[from] serde_json::Error),
#[error(transparent)]
UrlError(#[from] url::ParseError),
#[error(transparent)]
CronError(#[from] CronError),
#[error("returned invalid result (expected {expected:?}, found {found:?})")]
ResultError { expected: u64, found: u64 },
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn get_pool(
) -> Result<InternalPool, AsyncQueueError> {
match kind {
#[cfg(feature = "asynk-postgres")]
"PostgreSQL" => {
"postgres" => {
let pool = PoolOptions::<Postgres>::new()
.max_connections(_max_connections)
.connect(_uri)
Expand All @@ -255,7 +255,7 @@ async fn get_pool(
Ok(InternalPool::Pg(pool))
}
#[cfg(feature = "asynk-sqlite")]
"SQLite" => {
"sqlite" => {
let pool = PoolOptions::<Sqlite>::new()
.max_connections(_max_connections)
.connect(_uri)
Expand All @@ -264,7 +264,7 @@ async fn get_pool(
Ok(InternalPool::Sqlite(pool))
}
#[cfg(feature = "asynk-mysql")]
"MySql" => {
"mysql" => {
let pool = PoolOptions::<MySql>::new()
.max_connections(_max_connections)
.connect(_uri)
Expand All @@ -291,9 +291,9 @@ impl AsyncQueue {
pub async fn connect(&mut self) -> Result<(), AsyncQueueError> {
install_default_drivers();

let any_type_info: AnyTypeInfo = sqlx::Encode::<Any>::produces(&self.uri).unwrap();
let kind = Url::parse(&self.uri)?;

let kind: &str = any_type_info.name();
let kind = kind.scheme();

let pool = get_pool(kind, &self.uri, self.max_pool_size).await?;

Expand Down
9 changes: 4 additions & 5 deletions fang/src/asynk/backend_sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use {
};

use std::fmt::Debug;
use std::str::FromStr;
use typed_builder::TypedBuilder;
use uuid::Uuid;

Expand Down Expand Up @@ -103,14 +102,14 @@ impl BackendSqlX {
}
}

pub(crate) fn name(&self) -> &str {
pub(crate) fn _name(&self) -> &str {
match *self {
#[cfg(feature = "asynk-postgres")]
BackendSqlX::Pg => BackendSqlXPg::name(),
BackendSqlX::Pg => BackendSqlXPg::_name(),
#[cfg(feature = "asynk-sqlite")]
BackendSqlX::Sqlite => BackendSqlXSQLite::name(),
BackendSqlX::Sqlite => BackendSqlXSQLite::_name(),
#[cfg(feature = "asynk-mysql")]
BackendSqlX::MySql => BackendSqlXMySQL::name(),
BackendSqlX::MySql => BackendSqlXMySQL::_name(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fang/src/asynk/backend_sqlx/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl BackendSqlXMySQL {
}
}

pub(super) fn name() -> &'static str {
pub(super) fn _name() -> &'static str {
"MySQL"
}
}
2 changes: 1 addition & 1 deletion fang/src/asynk/backend_sqlx/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl BackendSqlXPg {
}
}

pub(super) fn name() -> &'static str {
pub(super) fn _name() -> &'static str {
"PostgreSQL"
}
}
2 changes: 1 addition & 1 deletion fang/src/asynk/backend_sqlx/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl BackendSqlXSQLite {
}
}

pub(super) fn name() -> &'static str {
pub(super) fn _name() -> &'static str {
"SQLite"
}
}

0 comments on commit 309e144

Please sign in to comment.