sea-query
sea-query copied to clipboard
Table Column with Default Expression
Motivation
- Currently, we support column with default value but not default expression
- Having default expression in column such as timestamp / datetime is very common, e.g.
CURRENT_TIMESTAMPas the default expression
Proposed Solutions
ColumnSpec::Default(Value)should be changed to holdingSimpleExpr, i.e.ColumnSpec::Default(SimpleExpr)https://github.com/SeaQL/sea-query/blob/6c9527ae08e32c55490ae510be41f646e030c2a2/src/table/column.rs#L48-L58- Keep the old
defaultmethod and introduce a new method calleddefault_exprwhich take anyInto<SimpleExpr>https://github.com/SeaQL/sea-query/blob/6c9527ae08e32c55490ae510be41f646e030c2a2/src/table/column.rs#L142-L149
@billy1624, hello! I will do this.
Thanks! @ikrivosheev
Related Discussion:
- https://github.com/SeaQL/sea-query/discussions/346
@billy1624 what do you think about new Enum for table? We only need some variants from SimpleExpr
- FuncionCall
- Value
- Custom
No, bad ideas... We need to split QueryBuilder. For unavailable operations panic.
Hey @ikrivosheev, sorry for the delay.
@billy1624 what do you think about new
Enumfor table? We only need some variants fromSimpleExpr
Do you mean introducing a new Enum for the "Default Value" of a column? https://github.com/SeaQL/sea-query/blob/63e18941fad55e391e4abb1316fd81e7a7768f91/src/table/column.rs#L51-L61
pub enum ColumnSpec {
...
Default(DefaultValue)
...
}
// I just makeup the name, feel free to rename it :)
pub enum DefaultValue {
Func(Function),
Value(Value),
Custom(String),
}
Something like this?
Hey @ikrivosheev, sorry for the delay.
@billy1624 what do you think about new
Enumfor table? We only need some variants fromSimpleExprDo you mean introducing a new
Enumfor the "Default Value" of a column?https://github.com/SeaQL/sea-query/blob/63e18941fad55e391e4abb1316fd81e7a7768f91/src/table/column.rs#L51-L61
pub enum ColumnSpec { ... Default(DefaultValue) ... } // I just makeup the name, feel free to rename it :) pub enum DefaultValue { Func(Function), Value(Value), Custom(String), }Something like this?
Yes
@billy1624 @tyt2y3 what do you think about custom Enum?
- I think we should rename the old
defaulttodefault_valueand the newdefaultis an alias ofdefault_expr - Yes I think having a dedicated
DefaultColumnExpris a good idea
@tyt2y3 @billy1624 hello! I have made several attempts and understand that is better to use SimpleExpr instead create DefaultColumnExpr
I have no objection to either
Hello @ikrivosheev, are you working on this?