Mejora y simplifica el soporte a bases de datos
This commit is contained in:
parent
34692551f6
commit
6a85db2b02
11 changed files with 31 additions and 20 deletions
|
|
@ -13,5 +13,7 @@ homepage = "https://suitepro.cillero.es/projects/pagetop"
|
|||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
license = "Apache-2.0 or MIT"
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
features = ["database"]
|
||||
default-features = false
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ homepage = "https://suitepro.cillero.es/projects/pagetop"
|
|||
repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||
license = "Apache-2.0 or MIT"
|
||||
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
features = ["database"]
|
||||
default-features = false
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -64,9 +64,10 @@ optional = true
|
|||
|
||||
[features]
|
||||
default = []
|
||||
mysql = ["sea-orm", "sea-orm-migration", "sea-orm/sqlx-mysql"]
|
||||
postgres = ["sea-orm", "sea-orm-migration", "sea-orm/sqlx-postgres"]
|
||||
sqlite = ["sea-orm", "sea-orm-migration", "sea-orm/sqlx-sqlite"]
|
||||
database = ["sea-orm", "sea-orm-migration"]
|
||||
mysql = ["database", "sea-orm/sqlx-mysql"]
|
||||
postgres = ["database", "sea-orm/sqlx-postgres"]
|
||||
sqlite = ["database", "sea-orm/sqlx-sqlite"]
|
||||
|
||||
[build-dependencies]
|
||||
static-files = "0.2.3"
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@ edition = "2021"
|
|||
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
# Si se usa base de datos:
|
||||
# Si requiere base de datos (MySql, Postgres y/o SQLite):
|
||||
features = ["mysql"]
|
||||
# features = ["postgres"]
|
||||
# features = ["sqlite"]
|
||||
# Soporte alternativo a todas las bases de datos:
|
||||
# features = ["mysql", "postgres", "sqlite"]
|
||||
# En estos casos hay que deshabilitar las características predeterminadas:
|
||||
# En este caso hay que deshabilitar las características predeterminadas:
|
||||
default-features = false
|
||||
|
||||
[dependencies]
|
||||
|
|
|
|||
|
|
@ -6,8 +6,14 @@ edition = "2021"
|
|||
# Ver más claves y sus definiciones en
|
||||
# https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.pagetop]
|
||||
path = "../pagetop"
|
||||
# Para dar soporte a bases de datos:
|
||||
features = ["database"]
|
||||
# En este caso hay que deshabilitar las características predeterminadas:
|
||||
default-features = false
|
||||
|
||||
[dependencies]
|
||||
pagetop = { path = "../pagetop" }
|
||||
# Si se usa la macro html!:
|
||||
maud = { git = "https://github.com/lambda-fairy/maud", rev = "e6787cd6" }
|
||||
# Si se requiere serialización de estructuras de datos:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod tracing;
|
|||
|
||||
pub mod locale;
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
pub mod db;
|
||||
|
||||
mod definition;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl Application {
|
|||
LazyStatic::force(&super::locale::LANGID);
|
||||
|
||||
// Conecta con la base de datos (opcional).
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
LazyStatic::force(&super::db::DBCONN);
|
||||
|
||||
// Habilita los módulos predeterminados.
|
||||
|
|
@ -46,7 +46,7 @@ impl Application {
|
|||
module::all::register_actions();
|
||||
|
||||
// Ejecuta actualizaciones pendientes de la base de datos (opcional).
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
module::all::run_migrations();
|
||||
|
||||
// Ejecuta la función de inicio de la aplicación.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use super::ModuleTrait;
|
|||
use crate::core::hook::add_action;
|
||||
use crate::{app, trace, LazyStatic};
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
use crate::{db::*, run_now};
|
||||
|
||||
use std::sync::RwLock;
|
||||
|
|
@ -66,7 +66,7 @@ pub fn register_actions() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
pub fn run_migrations() {
|
||||
run_now({
|
||||
struct Migrator;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::core::hook::HookAction;
|
||||
use crate::{app, util};
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
use crate::db::MigrationItem;
|
||||
|
||||
pub trait BaseModule {
|
||||
|
|
@ -31,7 +31,7 @@ pub trait ModuleTrait: BaseModule + Send + Sync {
|
|||
vec![]
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
#[allow(unused_variables)]
|
||||
fn migrations(&self) -> Vec<MigrationItem> {
|
||||
vec![]
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub mod locale;
|
|||
pub mod html;
|
||||
|
||||
// Acceso a base de datos.
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
pub mod db;
|
||||
|
||||
// Prepare and run the application.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub use crate::localize;
|
|||
|
||||
pub use crate::html::*;
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
#[cfg(feature = "database")]
|
||||
pub use crate::{db, db::*, migration_item, pub_migration};
|
||||
|
||||
pub use crate::app;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue