Skip to content

Commit

Permalink
sea-orm-codegen: PostgreSQL enum arrays (#1678)
Browse files Browse the repository at this point in the history
* sea-orm-codegen: PostgreSQL enum arrays

* Refactoring

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
  • Loading branch information
niklaskorz and billy1624 authored Jul 21, 2023
1 parent 217894d commit 73a5783
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ impl Column {
quote! {}
}
}

pub fn get_inner_col_type(&self) -> &ColumnType {
match &self.col_type {
ColumnType::Array(inner_col_type) => inner_col_type.as_ref(),
_ => &self.col_type,
}
}
}

impl From<ColumnDef> for Column {
Expand Down
3 changes: 2 additions & 1 deletion sea-orm-codegen/src/entity/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl EntityTransformer {
col
})
.map(|col| {
if let sea_query::ColumnType::Enum { name, variants } = &col.col_type {
if let sea_query::ColumnType::Enum { name, variants } = col.get_inner_col_type()
{
enums.insert(
name.to_string(),
ActiveEnum {
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl EntityWriter {
.columns
.iter()
.fold(TokenStream::new(), |mut ts, col| {
if let sea_query::ColumnType::Enum { name, .. } = &col.col_type {
if let sea_query::ColumnType::Enum { name, .. } = col.get_inner_col_type() {
let enum_name = format_ident!("{}", name.to_string().to_upper_camel_case());
ts.extend([quote! {
use super::sea_orm_active_enums::#enum_name;
Expand Down

0 comments on commit 73a5783

Please sign in to comment.