Skip to content

Commit

Permalink
codegen: fix ColumnType to Rust type resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Aug 7, 2024
1 parent 7e433df commit eb7d9d5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sea-orm-codegen/src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Column {

pub fn get_rs_type(&self, date_time_crate: &DateTimeCrate) -> TokenStream {
fn write_rs_type(col_type: &ColumnType, date_time_crate: &DateTimeCrate) -> String {
#[allow(unreachable_patterns)]
match col_type {
ColumnType::Char(_)
| ColumnType::String(_)
Expand Down Expand Up @@ -60,7 +59,6 @@ impl Column {
},
ColumnType::Timestamp => match date_time_crate {
DateTimeCrate::Chrono => "DateTimeUtc".to_owned(),
// ColumnType::Timpestamp(_) => time::PrimitiveDateTime: https://docs.rs/sqlx/0.3.5/sqlx/postgres/types/index.html#time
DateTimeCrate::Time => "TimeDateTime".to_owned(),
},
ColumnType::TimestampWithTimeZone => match date_time_crate {
Expand All @@ -77,7 +75,14 @@ impl Column {
ColumnType::Array(column_type) => {
format!("Vec<{}>", write_rs_type(column_type, date_time_crate))
}
_ => unimplemented!(),
ColumnType::Bit(None | Some(1)) => "bool".to_owned(),
ColumnType::Bit(_) | ColumnType::VarBit(_) => "Vec<u8>".to_owned(),
ColumnType::Year => "i32".to_owned(),
ColumnType::Interval(_, _)
| ColumnType::Cidr
| ColumnType::Inet
| ColumnType::MacAddr
| ColumnType::LTree => "String".to_owned(),
}
}
let ident: TokenStream = write_rs_type(&self.col_type, date_time_crate)
Expand Down

0 comments on commit eb7d9d5

Please sign in to comment.