sea-query icon indicating copy to clipboard operation
sea-query copied to clipboard

Table Column with Default Expression

Open billy1624 opened this issue 3 years ago • 10 comments

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_TIMESTAMP as the default expression

Proposed Solutions

  • ColumnSpec::Default(Value) should be changed to holding SimpleExpr, i.e. ColumnSpec::Default(SimpleExpr) https://github.com/SeaQL/sea-query/blob/6c9527ae08e32c55490ae510be41f646e030c2a2/src/table/column.rs#L48-L58
  • Keep the old default method and introduce a new method called default_expr which take any Into<SimpleExpr> https://github.com/SeaQL/sea-query/blob/6c9527ae08e32c55490ae510be41f646e030c2a2/src/table/column.rs#L142-L149

billy1624 avatar Jun 06 '22 02:06 billy1624

@billy1624, hello! I will do this.

ikrivosheev avatar Jun 06 '22 06:06 ikrivosheev

Thanks! @ikrivosheev

billy1624 avatar Jun 06 '22 08:06 billy1624

Related Discussion:

  • https://github.com/SeaQL/sea-query/discussions/346

billy1624 avatar Jun 06 '22 08:06 billy1624

@billy1624 what do you think about new Enum for table? We only need some variants from SimpleExpr

  1. FuncionCall
  2. Value
  3. Custom

ikrivosheev avatar Jun 21 '22 18:06 ikrivosheev

No, bad ideas... We need to split QueryBuilder. For unavailable operations panic.

ikrivosheev avatar Jun 21 '22 18:06 ikrivosheev

Hey @ikrivosheev, sorry for the delay.

@billy1624 what do you think about new Enum for table? We only need some variants from SimpleExpr

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?

billy1624 avatar Jun 27 '22 11:06 billy1624

Hey @ikrivosheev, sorry for the delay.

@billy1624 what do you think about new Enum for table? We only need some variants from SimpleExpr

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?

Yes

ikrivosheev avatar Jun 27 '22 11:06 ikrivosheev

@billy1624 @tyt2y3 what do you think about custom Enum?

ikrivosheev avatar Jul 04 '22 16:07 ikrivosheev

  1. I think we should rename the old default to default_value and the new default is an alias of default_expr
  2. Yes I think having a dedicated DefaultColumnExpr is a good idea

tyt2y3 avatar Jul 10 '22 07:07 tyt2y3

@tyt2y3 @billy1624 hello! I have made several attempts and understand that is better to use SimpleExpr instead create DefaultColumnExpr

ikrivosheev avatar Aug 10 '22 18:08 ikrivosheev

I have no objection to either

tyt2y3 avatar Aug 16 '22 01:08 tyt2y3

Hello @ikrivosheev, are you working on this?

billy1624 avatar Aug 29 '22 03:08 billy1624