From aea4ec2d54b4993bfcf110f973392c0ab3c56b69 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 17 Aug 2021 12:41:34 +0800 Subject: [PATCH] Codegen mod.rs include prelude --- sea-orm-codegen/src/entity/writer.rs | 9 ++++++++- sea-orm-codegen/tests/entity/mod.rs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index d277ddac..207864ba 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -44,11 +44,18 @@ impl EntityWriter { pub fn write_mod(&self) -> OutputFile { let mut lines = Vec::new(); Self::write_doc_comment(&mut lines); - let code_blocks = self + let code_blocks: Vec = self .entities .iter() .map(|entity| Self::gen_mod(entity)) .collect(); + Self::write( + &mut lines, + vec![quote! { + pub mod prelude; + }], + ); + lines.push("".to_owned()); Self::write(&mut lines, code_blocks); OutputFile { name: "mod.rs".to_owned(), diff --git a/sea-orm-codegen/tests/entity/mod.rs b/sea-orm-codegen/tests/entity/mod.rs index 395d29f9..5a8c6c21 100644 --- a/sea-orm-codegen/tests/entity/mod.rs +++ b/sea-orm-codegen/tests/entity/mod.rs @@ -1,5 +1,7 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 +pub mod prelude; + pub mod cake; pub mod cake_filling; pub mod filling;