Skip to content

Commit 88a691d

Browse files
committed
changed the directory structure of the generated entity files
Signed-off-by: involk-secure-1609 <[email protected]>
1 parent eddb6ca commit 88a691d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

sea-orm-cli/src/commands/generate.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,24 @@ pub async fn run_generate_command(
239239
);
240240
let output = EntityTransformer::transform(table_stmts)?.generate(&writer_context);
241241

242-
let dir = Path::new(&output_dir);
243-
fs::create_dir_all(dir)?;
242+
let entities_dir_path = output_dir.clone() + "/entities";
243+
244+
let output_dir = Path::new(&(output_dir));
245+
let entities_dir = Path::new(&(entities_dir_path));
246+
fs::create_dir_all(entities_dir)?;
244247

245248
for OutputFile { name, content } in output.files.iter() {
246-
let file_path = dir.join(name);
249+
let file_path = output_dir.join(name);
247250
println!("Writing {}", file_path.display());
248251
let mut file = fs::File::create(file_path)?;
249252
file.write_all(content.as_bytes())?;
250253
}
251254

252255
// Format each of the files
253256
for OutputFile { name, .. } in output.files.iter() {
254-
let exit_status = Command::new("rustfmt").arg(dir.join(name)).status()?; // Get the status code
257+
let exit_status = Command::new("rustfmt")
258+
.arg(output_dir.join(name))
259+
.status()?; // Get the status code
255260
if !exit_status.success() {
256261
// Propagate the error if any
257262
return Err(format!("Fail to format file `{name}`").into());

sea-orm-codegen/src/entity/writer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl EntityWriter {
229229
self.entities
230230
.iter()
231231
.map(|entity| {
232-
let entity_file = format!("{}.rs", entity.get_table_name_snake_case());
232+
let entity_file = format!("entities/{}.rs", entity.get_table_name_snake_case());
233233
let column_info = entity
234234
.columns
235235
.iter()
@@ -335,7 +335,7 @@ impl EntityWriter {
335335

336336
let file_name = match lib {
337337
true => "lib.rs".to_owned(),
338-
false => "mod.rs".to_owned(),
338+
false => "entities.rs".to_owned(),
339339
};
340340

341341
OutputFile {
@@ -363,7 +363,7 @@ impl EntityWriter {
363363
.collect();
364364
Self::write(&mut lines, code_blocks);
365365
OutputFile {
366-
name: "prelude.rs".to_owned(),
366+
name: "entities/prelude.rs".to_owned(),
367367
content: lines.join("\n"),
368368
}
369369
}

0 commit comments

Comments
 (0)