cargo fmt

This commit is contained in:
Billy Chan 2022-03-25 15:25:49 +08:00
parent 5a473ba754
commit 6091629adb
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
5 changed files with 30 additions and 32 deletions

View File

@ -150,10 +150,7 @@ impl EntityWriter {
pub fn write_sea_orm_active_enums(&self, with_serde: &WithSerde) -> OutputFile { pub fn write_sea_orm_active_enums(&self, with_serde: &WithSerde) -> OutputFile {
let mut lines = Vec::new(); let mut lines = Vec::new();
Self::write_doc_comment(&mut lines); Self::write_doc_comment(&mut lines);
Self::write( Self::write(&mut lines, vec![Self::gen_import(with_serde)]);
&mut lines,
vec![Self::gen_import(with_serde)],
);
lines.push("".to_owned()); lines.push("".to_owned());
let code_blocks = self let code_blocks = self
.enums .enums

View File

@ -4,8 +4,8 @@ use crate::{
}; };
use sea_query::{ use sea_query::{
extension::postgres::{Type, TypeCreateStatement}, extension::postgres::{Type, TypeCreateStatement},
Alias, ColumnDef, ForeignKeyCreateStatement, Iden, Index, TableCreateStatement, Alias, ColumnDef, ForeignKeyCreateStatement, Iden, Index, IndexCreateStatement,
IndexCreateStatement, TableCreateStatement,
}; };
impl Schema { impl Schema {
@ -36,8 +36,8 @@ impl Schema {
/// Creates the indexes from an Entity, returning an empty Vec if there are none /// Creates the indexes from an Entity, returning an empty Vec if there are none
/// to create. See [IndexCreateStatement] for more details /// to create. See [IndexCreateStatement] for more details
pub fn create_index_from_entity<E>(&self, entity: E) -> Vec<IndexCreateStatement> pub fn create_index_from_entity<E>(&self, entity: E) -> Vec<IndexCreateStatement>
where where
E: EntityTrait, E: EntityTrait,
{ {
create_index_from_entity(entity, self.backend) create_index_from_entity(entity, self.backend)
} }
@ -87,9 +87,12 @@ where
vec vec
} }
pub(crate) fn create_index_from_entity<E>(entity: E, _backend: DbBackend) -> Vec<IndexCreateStatement> pub(crate) fn create_index_from_entity<E>(
where entity: E,
E: EntityTrait, _backend: DbBackend,
) -> Vec<IndexCreateStatement>
where
E: EntityTrait,
{ {
let mut vec = Vec::new(); let mut vec = Vec::new();
for column in E::Column::iter() { for column in E::Column::iter() {
@ -111,7 +114,6 @@ pub(crate) fn create_index_from_entity<E>(entity: E, _backend: DbBackend) -> Vec
vec vec
} }
pub(crate) fn create_table_from_entity<E>(entity: E, backend: DbBackend) -> TableCreateStatement pub(crate) fn create_table_from_entity<E>(entity: E, backend: DbBackend) -> TableCreateStatement
where where
E: EntityTrait, E: EntityTrait,
@ -229,7 +231,11 @@ mod tests {
let schema = Schema::new(builder); let schema = Schema::new(builder);
assert_eq!( assert_eq!(
builder.build(&schema.create_table_from_entity(CakeFillingPrice)), builder.build(&schema.create_table_from_entity(CakeFillingPrice)),
builder.build(&get_cake_filling_price_stmt().table(CakeFillingPrice.table_ref()).to_owned()) builder.build(
&get_cake_filling_price_stmt()
.table(CakeFillingPrice.table_ref())
.to_owned()
)
); );
} }
} }
@ -271,7 +277,6 @@ mod tests {
.to_owned() .to_owned()
} }
#[test] #[test]
fn test_create_index_from_entity_table_ref() { fn test_create_index_from_entity_table_ref() {
for builder in [DbBackend::MySql, DbBackend::Postgres, DbBackend::Sqlite] { for builder in [DbBackend::MySql, DbBackend::Postgres, DbBackend::Sqlite] {
@ -279,37 +284,32 @@ mod tests {
assert_eq!( assert_eq!(
builder.build(&schema.create_table_from_entity(indexes::Entity)), builder.build(&schema.create_table_from_entity(indexes::Entity)),
builder.build(&get_indexes_stmt().table(indexes::Entity.table_ref()).to_owned()) builder.build(
&get_indexes_stmt()
.table(indexes::Entity.table_ref())
.to_owned()
)
); );
let stmts = schema.create_index_from_entity(indexes::Entity); let stmts = schema.create_index_from_entity(indexes::Entity);
assert_eq!(stmts.len(), 2); assert_eq!(stmts.len(), 2);
let idx: IndexCreateStatement = Index::create() let idx: IndexCreateStatement = Index::create()
.name("idx-indexes-index1_attr") .name("idx-indexes-index1_attr")
.table(indexes::Entity) .table(indexes::Entity)
.col(indexes::Column::Index1Attr) .col(indexes::Column::Index1Attr)
.to_owned(); .to_owned();
assert_eq!( assert_eq!(builder.build(&stmts[0]), builder.build(&idx));
builder.build(&stmts[0]),
builder.build(&idx)
);
let idx: IndexCreateStatement = Index::create() let idx: IndexCreateStatement = Index::create()
.name("idx-indexes-index2_attr") .name("idx-indexes-index2_attr")
.table(indexes::Entity) .table(indexes::Entity)
.col(indexes::Column::Index2Attr) .col(indexes::Column::Index2Attr)
.to_owned(); .to_owned();
assert_eq!( assert_eq!(builder.build(&stmts[1]), builder.build(&idx));
builder.build(&stmts[1]),
builder.build(&idx)
);
} }
} }
fn get_indexes_stmt() -> TableCreateStatement { fn get_indexes_stmt() -> TableCreateStatement {
Table::create() Table::create()
.col( .col(
@ -338,5 +338,4 @@ mod tests {
) )
.to_owned() .to_owned()
} }
} }

View File

@ -45,7 +45,7 @@ impl PrimaryKeyTrait for PrimaryKey {
} }
#[derive(Copy, Clone, Debug, EnumIter)] #[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation { } pub enum Relation {}
impl ColumnTrait for Column { impl ColumnTrait for Column {
type EntityName = Entity; type EntityName = Entity;
@ -61,7 +61,9 @@ impl ColumnTrait for Column {
} }
impl RelationTrait for Relation { impl RelationTrait for Relation {
fn def(&self) -> RelationDef { panic!() } fn def(&self) -> RelationDef {
panic!()
}
} }
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}

View File

@ -7,9 +7,9 @@ pub mod cake_filling_price;
pub mod entity_linked; pub mod entity_linked;
pub mod filling; pub mod filling;
pub mod fruit; pub mod fruit;
pub mod indexes;
pub mod rust_keyword; pub mod rust_keyword;
pub mod vendor; pub mod vendor;
pub mod indexes;
pub use cake::Entity as Cake; pub use cake::Entity as Cake;
pub use cake_expanded::Entity as CakeExpanded; pub use cake_expanded::Entity as CakeExpanded;