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