SeaQL / sea-orm

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

is Sea orm Json type can't insert text [] type #2211

Open joebnb opened 1 month ago

joebnb commented 1 month ago

Description

is Sea orm Json type can't insert text [] type

hello i'm trying to add a record into postgres database,which contain a json value,and i got problem when insert happen

// enum definiton
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "recipe_type")]
pub enum EnumType {
    #[sea_orm(string_value = "a")]
    A,
    #[sea_orm(string_value = "b")]
    B
}

//table
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "table_name")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(column_type = "JsonBinary")]
    pub name: Vec<EnumType>
}

// insert action
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertType {
     id:i32,
     pub name: Vec<EnumType>
}

i got:

{ severity: Error, code: "42804", message: "column \"type\" is of type jsonb but expression is of type text[]", detail: None, hint: Some("You will need to rewrite or cast the expression."), position: Some(Original(186)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("parse_target.c"), line: Some(586), routine: Some("transformAssignedExpr") }

it's seems text[] was not supported by seaorm ?

thanks for read,i did this follow issue 1517

https://github.com/SeaQL/sea-orm/issues/1517

anshap1719 commented 1 month ago

@joebnb Can you also provide the sea-orm version you're using?

anshap1719 commented 1 month ago

@joebnb Please also share the code where you're inserting the record.