🎨 (seaorm): Mejora API y documentación
- Reescribe la documentación con ejemplos completos, guía rápida y tablas de referencia. - Renombra `connection()` a `dbconn()`. - Añade `execute()` para SQL en crudo y corrige `fetch_all`/`fetch_one` para aceptar `&Q` en lugar de `&mut Q`. - Cambia `futures::executor::block_on` por `tokio::task::block_in_place` para compatibilidad con el *runtime* multi-hilo. - Los fallos de migración al arrancar provocan `panic!` en lugar de log de error silencioso. - Actualiza `#[pagetop::test]` para usar `flavor = "multi_thread"`, alineándolo con `#[pagetop::main]` y con las extensiones que usan SeaORM.
This commit is contained in:
parent
dfc1bdbc4c
commit
830602b24e
9 changed files with 602 additions and 178 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use futures::Future;
|
||||
use sea_orm::{
|
||||
AccessMode, ConnectionTrait, DatabaseConnection, DatabaseTransaction, DbBackend, DbErr,
|
||||
ExecResult, IsolationLevel, QueryResult, Statement, TransactionError, TransactionTrait,
|
||||
};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub enum SchemaManagerConnection<'c> {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use super::{IntoSchemaManagerConnection, SchemaManagerConnection};
|
||||
use sea_orm::sea_query::{
|
||||
extension::postgres::{TypeAlterStatement, TypeCreateStatement, TypeDropStatement},
|
||||
ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement, IndexDropStatement,
|
||||
SelectStatement, TableAlterStatement, TableCreateStatement, TableDropStatement,
|
||||
TableRenameStatement, TableTruncateStatement,
|
||||
extension::postgres::{TypeAlterStatement, TypeCreateStatement, TypeDropStatement},
|
||||
};
|
||||
use sea_orm::{ConnectionTrait, DbBackend, DbErr, StatementBuilder};
|
||||
#[allow(unused_imports)]
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use futures::Future;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use pagetop::trace::info;
|
||||
|
||||
use sea_orm::sea_query::{
|
||||
self, extension::postgres::Type, Alias, Expr, ExprTrait, ForeignKey, IntoIden, Order, Query,
|
||||
SelectStatement, SimpleExpr, Table,
|
||||
self, Alias, Expr, ExprTrait, ForeignKey, IntoIden, Order, Query, SelectStatement, SimpleExpr,
|
||||
Table, extension::postgres::Type,
|
||||
};
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ActiveValue, Condition, ConnectionTrait, DbBackend, DbErr, DeriveIden,
|
||||
|
|
@ -18,10 +18,10 @@ use sea_orm::{
|
|||
#[allow(unused_imports)]
|
||||
use sea_schema::probe::SchemaProbe;
|
||||
|
||||
use super::{seaql_migrations, IntoSchemaManagerConnection, MigrationTrait, SchemaManager};
|
||||
use super::{IntoSchemaManagerConnection, MigrationTrait, SchemaManager, seaql_migrations};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
/// Status of migration
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MigrationStatus {
|
||||
/// Not yet applied
|
||||
Pending,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
//! Adaptación de <https://github.com/loco-rs/loco/blob/master/src/schema.rs>
|
||||
//! Adapted from <https://github.com/loco-rs/loco/blob/master/src/schema.rs>
|
||||
//!
|
||||
//! # Ayudantes de esquema de base de datos
|
||||
//! # Database Table Schema Helpers
|
||||
//!
|
||||
//! Define funciones y ayudantes para crear esquemas de tablas usando `sea-orm` y `sea-query`.
|
||||
//! This module defines functions and helpers for creating database table
|
||||
//! schemas using the `sea-orm` and `sea-query` libraries.
|
||||
//!
|
||||
//! # Ejemplo
|
||||
//! # Example
|
||||
//!
|
||||
//! El siguiente ejemplo muestra cómo escribir un archivo de migración usando los ayudantes
|
||||
//! de esquema.
|
||||
//! The following example shows how the user migration file should be and using
|
||||
//! the schema helpers to create the Db fields.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use pagetop_seaorm::migration::*;
|
||||
|
|
@ -597,7 +598,7 @@ pub fn array_uniq<T: IntoIden>(col: T, elem_type: ColumnType) -> ColumnDef {
|
|||
array(col, elem_type).unique_key().take()
|
||||
}
|
||||
|
||||
/// Añade las columnas de timestamp (`CreatedAt` y `UpdatedAt`) a una tabla existente.
|
||||
/// Add timestamp columns (`CreatedAt` and `UpdatedAt`) to an existing table.
|
||||
pub fn timestamps(t: TableCreateStatement) -> TableCreateStatement {
|
||||
let mut t = t;
|
||||
t.col(timestamp(GeneralIds::CreatedAt).default(Expr::current_timestamp()))
|
||||
|
|
@ -605,7 +606,7 @@ pub fn timestamps(t: TableCreateStatement) -> TableCreateStatement {
|
|||
.take()
|
||||
}
|
||||
|
||||
/// Crea un alias.
|
||||
/// Create an Alias.
|
||||
pub fn name<T: Into<String>>(name: T) -> Alias {
|
||||
Alias::new(name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue