Skip to content

Commit

Permalink
Parse custom expression
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jun 9, 2023
1 parent 51e6b40 commit 146c081
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/mysql/parser/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,15 @@ pub fn parse_mysql_5_default(default: String, col_type: &Type) -> ColumnDefault
}

pub fn parse_mysql_8_default(default: String, extra: &str) -> ColumnDefault {
let is_expression = extra == "DEFAULT_GENERATED";
let is_expression = extra.contains("DEFAULT_GENERATED");
if is_expression && default == "CURRENT_TIMESTAMP" {
ColumnDefault::CurrentTimestamp
} else if let Ok(int) = default.parse::<i32>() {
ColumnDefault::Int(int)
} else if let Ok(double) = default.parse::<f64>() {
ColumnDefault::Double(double)
} else if is_expression {
ColumnDefault::CustomExpr(default)
} else {
ColumnDefault::String(default)
}
Expand All @@ -324,7 +326,7 @@ pub fn parse_mariadb_10_default(default: String) -> ColumnDefault {
} else if default == "NULL" {
ColumnDefault::Null
} else {
ColumnDefault::String(default)
ColumnDefault::CustomExpr(default)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/mysql/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::mysql::def::{CharSet, ColumnDefault, ColumnInfo, NumericAttr, StringAttr, Type};
use sea_query::{
Alias, BlobSize, ColumnDef, DynIden, EscapeBuilder, Iden, IntoIden, Keyword, MysqlQueryBuilder,
SimpleExpr,
SimpleExpr, Expr,
};
use std::fmt::Write;

Expand All @@ -21,6 +21,7 @@ impl ColumnInfo {
ColumnDefault::Int(int) => (*int).into(),
ColumnDefault::Double(double) => (*double).into(),
ColumnDefault::String(string) => string.into(),
ColumnDefault::CustomExpr(string) => Expr::cust(string),
ColumnDefault::Null => Option::<bool>::None.into(),
ColumnDefault::CurrentTimestamp => Keyword::CurrentTimestamp.into(),
};
Expand Down

0 comments on commit 146c081

Please sign in to comment.