Rename entity_to_table_create_statement

This commit is contained in:
Billy Chan 2021-09-06 22:41:01 +08:00 committed by Chris Tsang
parent 4a701d5e2d
commit b100e32ffd
5 changed files with 11 additions and 13 deletions

View File

@ -6,7 +6,6 @@ mod model;
pub mod prelude; pub mod prelude;
mod primary_key; mod primary_key;
mod relation; mod relation;
mod schema;
pub use active_model::*; pub use active_model::*;
pub use base_entity::*; pub use base_entity::*;
@ -16,4 +15,3 @@ pub use model::*;
// pub use prelude::*; // pub use prelude::*;
pub use primary_key::*; pub use primary_key::*;
pub use relation::*; pub use relation::*;
pub use schema::*;

View File

@ -214,6 +214,7 @@ pub mod entity;
pub mod error; pub mod error;
mod executor; mod executor;
pub mod query; pub mod query;
pub mod schema;
#[doc(hidden)] #[doc(hidden)]
pub mod tests_cfg; pub mod tests_cfg;
mod util; mod util;
@ -224,6 +225,7 @@ pub use entity::*;
pub use error::*; pub use error::*;
pub use executor::*; pub use executor::*;
pub use query::*; pub use query::*;
pub use schema::*;
pub use sea_orm_macros::{ pub use sea_orm_macros::{
DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn, DeriveCustomColumn, DeriveEntity, DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn, DeriveCustomColumn, DeriveEntity,

View File

@ -4,7 +4,7 @@ use crate::{
}; };
use sea_query::{ColumnDef, ForeignKeyCreateStatement, Iden, Index, TableCreateStatement}; use sea_query::{ColumnDef, ForeignKeyCreateStatement, Iden, Index, TableCreateStatement};
pub fn entity_to_table_create_statement<E>(entity: E) -> TableCreateStatement pub fn create_table_from_entity<E>(entity: E) -> TableCreateStatement
where where
E: EntityTrait, E: EntityTrait,
{ {
@ -112,14 +112,14 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{entity_to_table_create_statement, tests_cfg::*}; use crate::{create_table_from_entity, tests_cfg::*};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use sea_query::*; use sea_query::*;
#[test] #[test]
fn test_entity_to_table_create_statement() { fn test_create_table_from_entity() {
assert_eq!( assert_eq!(
entity_to_table_create_statement(CakeFillingPrice).to_string(MysqlQueryBuilder), create_table_from_entity(CakeFillingPrice).to_string(MysqlQueryBuilder),
Table::create() Table::create()
.table(CakeFillingPrice) .table(CakeFillingPrice)
.if_not_exists() .if_not_exists()

3
src/schema/mod.rs Normal file
View File

@ -0,0 +1,3 @@
mod entity;
pub use entity::*;

View File

@ -1,8 +1,6 @@
pub use super::super::bakery_chain::*; pub use super::super::bakery_chain::*;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use sea_orm::{ use sea_orm::{create_table_from_entity, error::*, sea_query, DbConn, EntityTrait, ExecResult};
entity_to_table_create_statement, error::*, sea_query, DbConn, EntityTrait, ExecResult,
};
use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement}; use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement};
async fn create_table<E>( async fn create_table<E>(
@ -15,10 +13,7 @@ where
{ {
let builder = db.get_database_backend(); let builder = db.get_database_backend();
let stmt = builder.build(stmt); let stmt = builder.build(stmt);
assert_eq!( assert_eq!(builder.build(&create_table_from_entity(entity)), stmt);
builder.build(&entity_to_table_create_statement(entity)),
stmt
);
db.execute(stmt).await db.execute(stmt).await
} }