From 309e1448267251f40ab699e91b400cc86ae89ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pepe=20M=C3=A1rquez=20Romero?= Date: Sat, 14 Dec 2024 18:46:58 +0100 Subject: [PATCH] make it work, with new without any warnings --- fang/Cargo.toml | 9 +++++++-- fang/src/asynk/async_queue.rs | 18 +++++++++--------- fang/src/asynk/backend_sqlx.rs | 9 ++++----- fang/src/asynk/backend_sqlx/mysql.rs | 2 +- fang/src/asynk/backend_sqlx/postgres.rs | 2 +- fang/src/asynk/backend_sqlx/sqlite.rs | 2 +- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/fang/Cargo.toml b/fang/Cargo.toml index 1802e3f..a505cfe 100644 --- a/fang/Cargo.toml +++ b/fang/Cargo.toml @@ -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", @@ -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] @@ -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", @@ -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" diff --git a/fang/src/asynk/async_queue.rs b/fang/src/asynk/async_queue.rs index 81a2690..62fa34a 100644 --- a/fang/src/asynk/async_queue.rs +++ b/fang/src/asynk/async_queue.rs @@ -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")] @@ -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 }, @@ -246,7 +246,7 @@ async fn get_pool( ) -> Result { match kind { #[cfg(feature = "asynk-postgres")] - "PostgreSQL" => { + "postgres" => { let pool = PoolOptions::::new() .max_connections(_max_connections) .connect(_uri) @@ -255,7 +255,7 @@ async fn get_pool( Ok(InternalPool::Pg(pool)) } #[cfg(feature = "asynk-sqlite")] - "SQLite" => { + "sqlite" => { let pool = PoolOptions::::new() .max_connections(_max_connections) .connect(_uri) @@ -264,7 +264,7 @@ async fn get_pool( Ok(InternalPool::Sqlite(pool)) } #[cfg(feature = "asynk-mysql")] - "MySql" => { + "mysql" => { let pool = PoolOptions::::new() .max_connections(_max_connections) .connect(_uri) @@ -291,9 +291,9 @@ impl AsyncQueue { pub async fn connect(&mut self) -> Result<(), AsyncQueueError> { install_default_drivers(); - let any_type_info: AnyTypeInfo = sqlx::Encode::::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?; diff --git a/fang/src/asynk/backend_sqlx.rs b/fang/src/asynk/backend_sqlx.rs index 1587ad6..ef138fc 100644 --- a/fang/src/asynk/backend_sqlx.rs +++ b/fang/src/asynk/backend_sqlx.rs @@ -7,7 +7,6 @@ use { }; use std::fmt::Debug; -use std::str::FromStr; use typed_builder::TypedBuilder; use uuid::Uuid; @@ -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(), } } } diff --git a/fang/src/asynk/backend_sqlx/mysql.rs b/fang/src/asynk/backend_sqlx/mysql.rs index f819256..c0d5140 100644 --- a/fang/src/asynk/backend_sqlx/mysql.rs +++ b/fang/src/asynk/backend_sqlx/mysql.rs @@ -448,7 +448,7 @@ impl BackendSqlXMySQL { } } - pub(super) fn name() -> &'static str { + pub(super) fn _name() -> &'static str { "MySQL" } } diff --git a/fang/src/asynk/backend_sqlx/postgres.rs b/fang/src/asynk/backend_sqlx/postgres.rs index daf5533..74d56a1 100644 --- a/fang/src/asynk/backend_sqlx/postgres.rs +++ b/fang/src/asynk/backend_sqlx/postgres.rs @@ -214,7 +214,7 @@ impl BackendSqlXPg { } } - pub(super) fn name() -> &'static str { + pub(super) fn _name() -> &'static str { "PostgreSQL" } } diff --git a/fang/src/asynk/backend_sqlx/sqlite.rs b/fang/src/asynk/backend_sqlx/sqlite.rs index 5a1773a..1d000e2 100644 --- a/fang/src/asynk/backend_sqlx/sqlite.rs +++ b/fang/src/asynk/backend_sqlx/sqlite.rs @@ -207,7 +207,7 @@ impl BackendSqlXSQLite { } } - pub(super) fn name() -> &'static str { + pub(super) fn _name() -> &'static str { "SQLite" } }