Skip to content

Commit

Permalink
Merge branch 'master' into enum_extra_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 authored Nov 8, 2023
2 parents 934b77a + 0dbfb42 commit bf615bd
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "path_matrix=$(find examples -mindepth 1 -maxdepth 1 -type d -printf '%P\0' | jq -Rc '[ split("\u0000") | .[] | "examples/\(.)" ]')" >> $GITHUB_OUTPUT
run: echo "path_matrix=$(find examples -mindepth 1 -maxdepth 1 -type d -not -path 'examples/rocket_okapi_example' -printf '%P\0' | jq -Rc '[ split("\u0000") | .[] | "examples/\(.)" ]')" >> $GITHUB_OUTPUT
outputs:
path_matrix: ${{ steps.set-matrix.outputs.path_matrix }}

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.12.6 - pending

### New Features

* Added `#[sea_orm(skip)]` for `FromQueryResult` derive macro https://github.com/SeaQL/sea-orm/pull/1954

### Bug Fixes

* [sea-orm-cli] Fix duplicated active enum use statements on generated entities https://github.com/SeaQL/sea-orm/pull/1953

## 0.12.5 - skipped

## 0.12.4 - 2023-10-19

### New Features
Expand Down
10 changes: 3 additions & 7 deletions examples/rocket_example/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ async-trait = { version = "0.1" }
rocket-example-service = { path = "../service" }
futures = { version = "0.3" }
futures-util = { version = "0.3" }
rocket = { version = "0.5.0-rc.1", features = [
"json",
] }
rocket_dyn_templates = { version = "0.1.0-rc.1", features = [
"tera",
] }
rocket = { version = "0.5.0-rc.4", features = ["json"] }
rocket_dyn_templates = { version = "0.1.0-rc.1", features = ["tera"] }
serde_json = { version = "1" }
entity = { path = "../entity" }
migration = { path = "../migration" }
tokio = "1.29.0"

[dependencies.sea-orm-rocket]
path = "../../../sea-orm-rocket/lib" # remove this line in your own project and uncomment the following line
# version = "0.5.2"
# version = "0.5.3"
4 changes: 1 addition & 3 deletions examples/rocket_example/entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ name = "entity"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.1", features = [
"json",
] }
rocket = { version = "0.5.0-rc.4", features = ["json"] }

[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
Expand Down
2 changes: 1 addition & 1 deletion examples/rocket_example/migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "migration"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.1" }
rocket = { version = "0.5.0-rc.4" }
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
Expand Down
16 changes: 7 additions & 9 deletions examples/rocket_okapi_example/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ async-trait = { version = "0.1" }
rocket-okapi-example-service = { path = "../service" }
futures = { version = "0.3" }
futures-util = { version = "0.3" }
rocket = { version = "0.5.0-rc.1", features = [
"json",
] }
rocket_dyn_templates = { version = "0.1.0-rc.1", features = [
"tera",
] }
rocket = { version = "0.5.0-rc.4", features = ["json"] }
rocket_dyn_templates = { version = "0.1.0-rc.1", features = ["tera"] }
serde_json = { version = "1" }
entity = { path = "../entity" }
migration = { path = "../migration" }
Expand All @@ -26,14 +22,16 @@ dto = { path = "../dto" }

[dependencies.sea-orm-rocket]
path = "../../../sea-orm-rocket/lib" # remove this line in your own project and use the version line
features = ["rocket_okapi"] # enables rocket_okapi so to have open api features enabled
features = [
"rocket_okapi",
] # enables rocket_okapi so to have open api features enabled
# version = "0.5.1"

[dependencies.rocket_okapi]
version = "0.8.0-rc.2"
features = ["swagger", "rapidoc","rocket_db_pools"]
features = ["swagger", "rapidoc", "rocket_db_pools"]

[dependencies.rocket_cors]
git = "https://github.com/lawliet89/rocket_cors.git"
rev = "54fae070"
default-features = false
default-features = false
6 changes: 2 additions & 4 deletions examples/rocket_okapi_example/dto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ name = "dto"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.1", features = [
"json",
] }
rocket = { version = "0.5.0-rc.4", features = ["json"] }

[dependencies.entity]
path = "../entity"

[dependencies.rocket_okapi]
version = "0.8.0-rc.2"
version = "0.8.0-rc.2"
4 changes: 1 addition & 3 deletions examples/rocket_okapi_example/entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ name = "entity"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.1", features = [
"json",
] }
rocket = { version = "0.5.0-rc.4", features = ["json"] }

[dependencies.sea-orm]
path = "../../../" # remove this line in your own project
Expand Down
2 changes: 1 addition & 1 deletion examples/rocket_okapi_example/migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "migration"
path = "src/lib.rs"

[dependencies]
rocket = { version = "0.5.0-rc.1" }
rocket = { version = "0.5.0-rc.4" }
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
Expand Down
7 changes: 7 additions & 0 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ pub enum GenerateSubcommands {
)]
model_extra_attributes: Vec<String>,

#[arg(
long,
value_delimiter = ',',
help = "Add extra derive macros to generated enums (comma separated), e.g. `--enum-extra-derives 'ts_rs::Ts','CustomDerive'`"
)]
enum_extra_derives: Vec<String>,

#[arg(
long,
value_delimiter = ',',
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub async fn run_generate_command(
lib,
model_extra_derives,
model_extra_attributes,
enum_extra_derives,
enum_extra_attributes,
seaography,
} => {
Expand Down Expand Up @@ -181,6 +182,7 @@ pub async fn run_generate_command(
serde_skip_hidden_column,
model_extra_derives,
model_extra_attributes,
enum_extra_derives,
enum_extra_attributes,
seaography,
);
Expand Down
48 changes: 43 additions & 5 deletions sea-orm-codegen/src/entity/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl ActiveEnum {
&self,
with_serde: &WithSerde,
with_copy_enums: bool,
enum_extra_attributes: &TokenStream,
extra_derives: &TokenStream,
extra_attributes: &TokenStream,
) -> TokenStream {
let enum_name = &self.enum_name.to_string();
let enum_iden = format_ident!("{}", enum_name.to_upper_camel_case());
Expand All @@ -29,17 +30,17 @@ impl ActiveEnum {
}
});

let extra_derive = with_serde.extra_derive();
let serde_derive = with_serde.extra_derive();
let copy_derive = if with_copy_enums {
quote! { , Copy }
} else {
quote! {}
};

quote! {
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum #copy_derive #extra_derive)]
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum #copy_derive #serde_derive #extra_derives)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = #enum_name)]
#enum_extra_attributes
#extra_attributes
pub enum #enum_iden {
#(
#[sea_orm(string_value = #values)]
Expand All @@ -52,6 +53,8 @@ impl ActiveEnum {

#[cfg(test)]
mod tests {
use crate::entity::writer::bonus_derive;

use super::*;
use crate::entity::writer::bonus_attributes;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -79,7 +82,7 @@ mod tests {
.map(|variant| Alias::new(variant).into_iden())
.collect(),
}
.impl_active_enum(&WithSerde::None, true, &TokenStream::new())
.impl_active_enum(&WithSerde::None, true, &TokenStream::new(), &TokenStream::new())
.to_string(),
quote!(
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy)]
Expand Down Expand Up @@ -113,6 +116,41 @@ mod tests {
)
}

#[test]
fn test_enum_extra_derives() {
assert_eq!(
ActiveEnum {
enum_name: Alias::new("media_type").into_iden(),
values: vec!["UNKNOWN", "BITMAP",]
.into_iter()
.map(|variant| Alias::new(variant).into_iden())
.collect(),
}
.impl_active_enum(
&WithSerde::None,
true,
&bonus_derive(["specta::Type", "ts_rs::TS"])
)
.to_string(),
build_generated_enum(),
);

#[rustfmt::skip]
fn build_generated_enum() -> String {
quote!(
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, specta :: Type, ts_rs :: TS)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "media_type")]
pub enum MediaType {
#[sea_orm(string_value = "UNKNOWN")]
Unknown,
#[sea_orm(string_value = "BITMAP")]
Bitmap,
}
)
.to_string()
}
}

#[test]
fn test_enum_extra_attributes() {
assert_eq!(
Expand Down
Loading

0 comments on commit bf615bd

Please sign in to comment.