SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.37k stars 517 forks source link

sea-orm-cli 1.0 generate entity from mysql generates String for MediumBlob fields #2318

Open PitayaDEV opened 3 months ago

PitayaDEV commented 3 months ago

I defined a mediumblob field using this code:

ColumnDef::new(MyTable::SharingPhoto).custom(MySqlType::MediumBlob)

When I generate an entity file using the command

sea-orm-cli generate entity --with-serde=both -l -o ./entity/src/

the type of the field in the generated entity file becomes a String type:

pub struct Model {
    #[sea_orm(column_type = "custom(\"mediumblob\")")]
    pub sharing_photo: Option<String>,
}

Under such circumstances, if I query data from the database, this error occurs:

error=Query Error: error occurred while decoding column "sharing_photo": mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `VARCHAR`) is not compatible with SQL type `BLOB`
Losses commented 2 weeks ago

Same bug happens on SQLite

sea-orm-bug-cursor-by.zip

image

This should NOT be

    #[sea_orm(column_type = "custom(\"binary(16777216)\")")]
    pub binary: String,

but

    #[sea_orm(column_type = "Blob")]
    pub binary: Vec<u8>,

A minimum reproduce is attached.