Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: codegen write binary column definition #1529

Merged
merged 1 commit into from
Mar 10, 2023
Merged

fix: codegen write binary column definition #1529

merged 1 commit into from
Mar 10, 2023

Conversation

billy1624
Copy link
Member

PR Info

Bug Fixes

  • The CLI command sea-orm-cli generate entity -u '<DB-URL>' will now generate the following code for each Binary or VarBinary columns in compact format
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "binary")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
    pub binary: Vec<u8>,
    #[sea_orm(column_type = "Binary(BlobSize::Blob(Some(10)))")]
    pub binary_10: Vec<u8>,
    #[sea_orm(column_type = "Binary(BlobSize::Tiny)")]
    pub binary_tiny: Vec<u8>,
    #[sea_orm(column_type = "Binary(BlobSize::Medium)")]
    pub binary_medium: Vec<u8>,
    #[sea_orm(column_type = "Binary(BlobSize::Long)")]
    pub binary_long: Vec<u8>,
    #[sea_orm(column_type = "VarBinary(10)")]
    pub var_binary: Vec<u8>,
}
  • The CLI command sea-orm-cli generate entity -u '<DB-URL>' --expanded-format will now generate the following code for each Binary or VarBinary columns in expanded format
impl ColumnTrait for Column {
    type EntityName = Entity;
    fn def(&self) -> ColumnDef {
        match self {
            Self::Id => ColumnType::Integer.def(),
            Self::Binary => ColumnType::Binary(sea_orm::sea_query::BlobSize::Blob(None)).def(),
            Self::Binary10 => {
                ColumnType::Binary(sea_orm::sea_query::BlobSize::Blob(Some(10u32))).def()
            }
            Self::BinaryTiny => ColumnType::Binary(sea_orm::sea_query::BlobSize::Tiny).def(),
            Self::BinaryMedium => ColumnType::Binary(sea_orm::sea_query::BlobSize::Medium).def(),
            Self::BinaryLong => ColumnType::Binary(sea_orm::sea_query::BlobSize::Long).def(),
            Self::VarBinary => ColumnType::VarBinary(10u32).def(),
        }
    }
}

@billy1624 billy1624 self-assigned this Mar 9, 2023
@billy1624 billy1624 force-pushed the issues/1528 branch 2 times, most recently from 0e35db8 to c9a3ab5 Compare March 9, 2023 06:14
@tyt2y3
Copy link
Member

tyt2y3 commented Mar 10, 2023

We can make a patch release

@billy1624 billy1624 marked this pull request as ready for review March 10, 2023 10:01
@billy1624 billy1624 merged commit 4b9038e into master Mar 10, 2023
@billy1624 billy1624 deleted the issues/1528 branch March 10, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Binary column type is generated without blob size
2 participants