From fefb3ed24940c85b50a39b8ce2db01cc75ea1422 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 16 Jul 2023 08:44:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Integrate=20futures=20libr?= =?UTF-8?q?ary=20with=20the=20database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/Cargo.toml | 8 +++++--- pagetop/src/core/module/all.rs | 2 +- pagetop/src/db.rs | 4 +++- pagetop/src/lib.rs | 24 ++++++++++++++---------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pagetop/Cargo.toml b/pagetop/Cargo.toml index aa7a9f5e..ad62a28b 100644 --- a/pagetop/Cargo.toml +++ b/pagetop/Cargo.toml @@ -27,7 +27,7 @@ name = "pagetop" [features] default = [] -database = ["sea-orm", "sea-schema"] +database = ["futures", "sea-orm", "sea-schema"] mysql = ["database", "sea-orm/sqlx-mysql"] postgres = ["database", "sea-orm/sqlx-postgres"] sqlite = ["database", "sea-orm/sqlx-sqlite"] @@ -37,8 +37,6 @@ async-trait = "0.1.68" concat-string = "1.0.1" figlet-rs = "0.1.5" itoa = "1.0.6" -futures = "0.3.28" -futures-util = "0.3.28" nom = "7.1.3" once_cell = "1.17.2" paste = "1.0.12" @@ -67,6 +65,10 @@ pagetop-macros = { version = "0.0", path = "../pagetop-macros" } serde = { version = "1.0", features = ["derive"] } +[dependencies.futures] +version = "0.3.28" +optional = true + [dependencies.sea-orm] version = "0.11.3" features = ["debug-print", "macros", "runtime-async-std-native-tls"] diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 6575b3a9..e5bbcabb 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -4,7 +4,7 @@ use crate::core::theme::all::THEMES; use crate::{service, trace, LazyStatic}; #[cfg(feature = "database")] -use crate::{db::*, run_now}; +use crate::{db::*}; use std::sync::RwLock; diff --git a/pagetop/src/db.rs b/pagetop/src/db.rs index c94c73ad..701cb4fc 100644 --- a/pagetop/src/db.rs +++ b/pagetop/src/db.rs @@ -1,6 +1,6 @@ //! Acceso unificado y normalizado a base de datos. -use crate::{config, run_now, trace, LazyStatic, ResultExt}; +use crate::{config, trace, LazyStatic, ResultExt}; pub use url::Url as DbUri; @@ -8,6 +8,8 @@ pub use sea_orm::{DatabaseConnection as DbConn, ExecResult, QueryResult}; use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement}; +pub(crate) use futures::executor::block_on as run_now; + pub(crate) static DBCONN: LazyStatic = LazyStatic::new(|| { trace::info!( "Connecting to database \"{}\" using a pool of {} connections", diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index a82ef463..8557aaee 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -98,28 +98,32 @@ //! PageTop a estructurar e inicializar modularmente la aplicación. // ************************************************************************************************* -// GLOBAL. +// RE-EXPORTED MACROS. // ************************************************************************************************* pub use concat_string::concat_string; -pub use once_cell::sync::Lazy as LazyStatic; -pub use paste::paste; -pub use static_files::Resource as StaticResource; -pub use tracing_unwrap::ResultExt; -#[allow(unused_imports)] -pub(crate) use futures::executor::block_on as run_now; +/// Enables flexible identifier concatenation in macros, allowing new items with pasted identifiers. +pub use paste::paste; pub use pagetop_macros::fn_builder; -pub type HashMapResources = std::collections::HashMap<&'static str, StaticResource>; +// ************************************************************************************************* +// GLOBAL. +// ************************************************************************************************* + +pub use once_cell::sync::Lazy as LazyStatic; +pub use static_files::Resource as StaticResource; +pub use tracing_unwrap::ResultExt; pub type Handle = u64; +pub type Weight = i8; +pub type HashMapResources = std::collections::HashMap<&'static str, StaticResource>; static_locales!(LOCALES_PAGETOP); // ************************************************************************************************* -// APIs PÚBLICAS. +// PUBLIC API. // ************************************************************************************************* // Gestión de la configuración. @@ -151,7 +155,7 @@ pub mod util; pub mod app; // ************************************************************************************************* -// RE-EXPORTA API ÚNICA. +// The PageTop Prelude. // ************************************************************************************************* pub mod prelude;