sea-orm-codegen: PostgreSQL enum arrays (#1678)

* sea-orm-codegen: PostgreSQL enum arrays

* Refactoring

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
This commit is contained in:
Niklas Korz 2023-07-21 15:45:11 +02:00 committed by GitHub
parent 217894ddad
commit 73a57836fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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;