Skip to content

Commit

Permalink
Generate arbitrary named entity (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Aug 10, 2021
1 parent b1d28db commit 9be094b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ clap = { version = "^2.33.3" }
dotenv = { version = "^0.15" }
async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm = { version = "^0.1", features = [ "sqlx-all" ] }
sea-orm-codegen = { version = "^0.1" }
sea-orm-codegen = { path = "../sea-orm-codegen", version = "^0.1" }
sea-schema = { version = "^0.2.4", default-features = false, features = [
"sqlx-mysql",
"sqlx-postgres",
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ cargo run -- -h
Running Entity Generator:

```sh
cargo run -- entity generate -url mysql://sea:sea@localhost/bakery -schema bakery -o out
cargo run -- generate entity -u mysql://sea:sea@localhost/bakery -s bakery -o out
```
8 changes: 4 additions & 4 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl EntityWriter {
let code_blocks = Self::gen_code_blocks(entity);
Self::write(&mut lines, code_blocks);
OutputFile {
name: format!("{}.rs", entity.table_name),
name: format!("{}.rs", entity.get_table_name_snake_case()),
content: lines.join("\n\n"),
}
})
Expand Down Expand Up @@ -123,11 +123,11 @@ impl EntityWriter {
}

pub fn gen_impl_entity_name(entity: &Entity) -> TokenStream {
let table_name_snake_case = entity.get_table_name_snake_case();
let table_name = entity.table_name.as_str();
quote! {
impl EntityName for Entity {
fn table_name(&self) -> &str {
#table_name_snake_case
#table_name
}
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ mod tests {
}],
},
Entity {
table_name: "cake_filling".to_owned(),
table_name: "_cake_filling_".to_owned(),
columns: vec![
Column {
name: "cake_id".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/tests/entity/cake_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Entity;

impl EntityName for Entity {
fn table_name(&self) -> &str {
"cake_filling"
"_cake_filling_"
}
}

Expand Down

0 comments on commit 9be094b

Please sign in to comment.