From ba226a2b62e882586768f08cdde3369c7a901736 Mon Sep 17 00:00:00 2001 From: Billy Chan <30400950+billy1624@users.noreply.github.com> Date: Tue, 10 Aug 2021 16:35:10 +0800 Subject: [PATCH] Generate arbitrary named entity (#70) * Generate arbitrary named entity (#69) * Bump cli & codegen version * CI tests no caching * Remove local dependency path --- .github/workflows/rust.yml | 10 ---------- sea-orm-cli/Cargo.toml | 2 +- sea-orm-cli/README.md | 2 +- sea-orm-codegen/Cargo.toml | 2 +- sea-orm-codegen/src/entity/writer.rs | 8 ++++---- sea-orm-codegen/tests/entity/cake_filling.rs | 2 +- 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8333661cb..11315fc3d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,8 +25,6 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 with: command: build @@ -60,8 +58,6 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 with: command: build @@ -109,8 +105,6 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 with: command: build @@ -158,8 +152,6 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 with: command: build @@ -204,8 +196,6 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/cargo@v1 with: command: build diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 48be929ef..240eba62f 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sea-orm-cli" -version = "0.1.0" +version = "0.1.1" authors = [ "Billy Chan " ] edition = "2018" description = "Command line utility for SeaORM" diff --git a/sea-orm-cli/README.md b/sea-orm-cli/README.md index b63a5c56c..f5c64e527 100644 --- a/sea-orm-cli/README.md +++ b/sea-orm-cli/README.md @@ -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 ``` diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index ee48571f1..3511b6148 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sea-orm-codegen" -version = "0.1.1" +version = "0.1.2" authors = ["Billy Chan "] edition = "2018" description = "Code Generator for SeaORM" diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index f4167b615..d277ddace 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -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"), } }) @@ -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 } } } @@ -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(), diff --git a/sea-orm-codegen/tests/entity/cake_filling.rs b/sea-orm-codegen/tests/entity/cake_filling.rs index 1ac649207..d0f00560b 100644 --- a/sea-orm-codegen/tests/entity/cake_filling.rs +++ b/sea-orm-codegen/tests/entity/cake_filling.rs @@ -7,7 +7,7 @@ pub struct Entity; impl EntityName for Entity { fn table_name(&self) -> &str { - "cake_filling" + "_cake_filling_" } }