Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
qqxhb committed Jan 27, 2024
1 parent cfff5e0 commit b842b51
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 333 deletions.
32 changes: 16 additions & 16 deletions field/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,90 +48,90 @@ func NewAsterisk(table string, opts ...Option) Asterisk {

// NewInt create new Int
func NewInt(table, column string, opts ...Option) Int {
return Int{GenericsInt[int]{GenericsField: GenericsField[int]{expr{col: toColumn(table, column, opts...)}}}}
return Int{NewGenericsInt[int](expr{col: toColumn(table, column, opts...)})}
}

// NewInt8 create new Int8
func NewInt8(table, column string, opts ...Option) Int8 {
return Int8{GenericsInt[int8]{GenericsField: GenericsField[int8]{expr{col: toColumn(table, column, opts...)}}}}
return Int8{NewGenericsInt[int8](expr{col: toColumn(table, column, opts...)})}
}

// NewInt16 ...
func NewInt16(table, column string, opts ...Option) Int16 {
return Int16{GenericsInt[int16]{GenericsField: GenericsField[int16]{expr{col: toColumn(table, column, opts...)}}}}
return Int16{NewGenericsInt[int16](expr{col: toColumn(table, column, opts...)})}
}

// NewInt32 ...
func NewInt32(table, column string, opts ...Option) Int32 {
return Int32{GenericsInt[int32]{GenericsField: GenericsField[int32]{expr{col: toColumn(table, column, opts...)}}}}
return Int32{NewGenericsInt[int32](expr{col: toColumn(table, column, opts...)})}
}

// NewInt64 ...
func NewInt64(table, column string, opts ...Option) Int64 {
return Int64{GenericsInt[int64]{GenericsField: GenericsField[int64]{expr{col: toColumn(table, column, opts...)}}}}
return Int64{NewGenericsInt[int64](expr{col: toColumn(table, column, opts...)})}
}

// NewUint ...
func NewUint(table, column string, opts ...Option) Uint {
return Uint{GenericsInt[uint]{GenericsField: GenericsField[uint]{expr{col: toColumn(table, column, opts...)}}}}
return Uint{NewGenericsInt[uint](expr{col: toColumn(table, column, opts...)})}
}

// NewUint8 ...
func NewUint8(table, column string, opts ...Option) Uint8 {
return Uint8{GenericsInt[uint8]{GenericsField: GenericsField[uint8]{expr{col: toColumn(table, column, opts...)}}}}
return Uint8{NewGenericsInt[uint8](expr{col: toColumn(table, column, opts...)})}
}

// NewUint16 ...
func NewUint16(table, column string, opts ...Option) Uint16 {
return Uint16{GenericsInt[uint16]{GenericsField: GenericsField[uint16]{expr{col: toColumn(table, column, opts...)}}}}
return Uint16{NewGenericsInt[uint16](expr{col: toColumn(table, column, opts...)})}
}

// NewUint32 ...
func NewUint32(table, column string, opts ...Option) Uint32 {
return Uint32{GenericsInt[uint32]{GenericsField: GenericsField[uint32]{expr{col: toColumn(table, column, opts...)}}}}
return Uint32{NewGenericsInt[uint32](expr{col: toColumn(table, column, opts...)})}
}

// NewUint64 ...
func NewUint64(table, column string, opts ...Option) Uint64 {
return Uint64{GenericsInt[uint64]{GenericsField: GenericsField[uint64]{expr{col: toColumn(table, column, opts...)}}}}
return Uint64{NewGenericsInt[uint64](expr{col: toColumn(table, column, opts...)})}
}

// ======================== float =======================

// NewFloat32 ...
func NewFloat32(table, column string, opts ...Option) Float32 {
return Float32{GenericsInt[float32]{GenericsField: GenericsField[float32]{expr{col: toColumn(table, column, opts...)}}}}
return Float32{NewGenericsInt[float32](expr{col: toColumn(table, column, opts...)})}
}

// NewFloat64 ...
func NewFloat64(table, column string, opts ...Option) Float64 {
return Float64{GenericsInt[float64]{GenericsField: GenericsField[float64]{expr{col: toColumn(table, column, opts...)}}}}
return Float64{NewGenericsInt[float64](expr{col: toColumn(table, column, opts...)})}
}

// ======================== string =======================

// NewString ...
func NewString(table, column string, opts ...Option) String {
return String{GenericsString[string]{GenericsField: GenericsField[string]{expr{col: toColumn(table, column, opts...)}}}}
return String{NewGenericsString[string](expr{col: toColumn(table, column, opts...)})}
}

// NewBytes ...
func NewBytes(table, column string, opts ...Option) Bytes {
return Bytes{GenericsString[[]byte]{GenericsField: GenericsField[[]byte]{expr{col: toColumn(table, column, opts...)}}}}
return Bytes{NewGenericsString[[]byte](expr{col: toColumn(table, column, opts...)})}
}

// ======================== bool =======================

// NewBool ...
func NewBool(table, column string, opts ...Option) Bool {
return Bool{GenericsField[bool]{expr{col: toColumn(table, column, opts...)}}}
return Bool{NewGenerics[bool](expr{col: toColumn(table, column, opts...)})}
}

// ======================== time =======================

// NewTime ...
func NewTime(table, column string, opts ...Option) Time {
return Time{GenericsField[time.Time]{expr{col: toColumn(table, column, opts...)}}}
return Time{NewGenerics[time.Time](expr{col: toColumn(table, column, opts...)})}
}

func toColumn(table, column string, opts ...Option) clause.Column {
Expand Down
17 changes: 10 additions & 7 deletions field/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,34 @@ func (e expr) IsNotNull() Expr {
}

func (e expr) Count() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{e.setE(clause.Expr{SQL: "COUNT(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Int{NewGenericsInt[int](e.setE(clause.Expr{SQL: "COUNT(?)", Vars: []interface{}{e.RawExpr()}}))}
}

func (e expr) Distinct() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{e.setE(clause.Expr{SQL: "DISTINCT ?", Vars: []interface{}{e.RawExpr()}})}}}
return Int{NewGenericsInt[int](e.setE(clause.Expr{SQL: "DISTINCT ?", Vars: []interface{}{e.RawExpr()}}))}

}

func (e expr) Length() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{e.setE(clause.Expr{SQL: "LENGTH(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Int{NewGenericsInt[int](e.setE(clause.Expr{SQL: "LENGTH(?)", Vars: []interface{}{e.RawExpr()}}))}
}

func (e expr) Max() Float64 {
return Float64{GenericsInt: GenericsInt[float64]{GenericsField: GenericsField[float64]{e.setE(clause.Expr{SQL: "MAX(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Float64{NewGenericsInt[float64](e.setE(clause.Expr{SQL: "MAX(?)", Vars: []interface{}{e.RawExpr()}}))}
}

func (e expr) Min() Float64 {
return Float64{GenericsInt: GenericsInt[float64]{GenericsField: GenericsField[float64]{e.setE(clause.Expr{SQL: "MIN(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Float64{NewGenericsInt[float64](e.setE(clause.Expr{SQL: "MIN(?)", Vars: []interface{}{e.RawExpr()}}))}

}

func (e expr) Avg() Float64 {
return Float64{GenericsInt: GenericsInt[float64]{GenericsField: GenericsField[float64]{e.setE(clause.Expr{SQL: "AVG(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Float64{NewGenericsInt[float64](e.setE(clause.Expr{SQL: "AVG(?)", Vars: []interface{}{e.RawExpr()}}))}

}

func (e expr) Abs() Float64 {
return Float64{GenericsInt: GenericsInt[float64]{GenericsField: GenericsField[float64]{e.setE(clause.Expr{SQL: "ABS(?)", Vars: []interface{}{e.RawExpr()}})}}}
return Float64{NewGenericsInt[float64](e.setE(clause.Expr{SQL: "ABS(?)", Vars: []interface{}{e.RawExpr()}}))}
}

func (e expr) Null() AssignExpr {
Expand Down
4 changes: 2 additions & 2 deletions field/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Float64 struct {

// Floor ...
func (field Float64) Floor() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{field.floor()}}}
return Int{NewGenericsInt[int](field.floor())}
}

// Float32 float32 type field
Expand All @@ -17,5 +17,5 @@ type Float32 struct {

// Floor ...
func (field Float32) Floor() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{field.floor()}}}
return Int{NewGenericsInt[int](field.floor())}
}
12 changes: 12 additions & 0 deletions field/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type ScanValuer interface {
Value() (driver.Value, error) // driver.Valuer
}

func NewGenerics[T any](e expr) GenericsField[T] {

Check failure on line 16 in field/generics.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] field/generics.go#L16

exported: exported function NewGenerics should have comment or be unexported (revive)
Raw output
field/generics.go:16:1: exported: exported function NewGenerics should have comment or be unexported (revive)
func NewGenerics[T any](e expr) GenericsField[T] {
^
return GenericsField[T]{e}
}

// GenericsField a generics field struct
type GenericsField[T any] struct{ expr }

Expand Down Expand Up @@ -84,6 +88,10 @@ func (field GenericsField[T]) toSlice(values ...T) []interface{} {
return slice
}

func NewGenericsInt[T any](e expr) GenericsInt[T] {

Check failure on line 91 in field/generics.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] field/generics.go#L91

exported: exported function NewGenericsInt should have comment or be unexported (revive)
Raw output
field/generics.go:91:1: exported: exported function NewGenericsInt should have comment or be unexported (revive)
func NewGenericsInt[T any](e expr) GenericsInt[T] {
^
return GenericsInt[T]{GenericsField: NewGenerics[T](e)}
}

// GenericsInt int type field
type GenericsInt[T any] struct {
GenericsField[T]
Expand Down Expand Up @@ -169,6 +177,10 @@ func (field GenericsInt[T]) Zero() AssignExpr {
return field.value(0)
}

func NewGenericsString[T any](e expr) GenericsString[T] {

Check failure on line 180 in field/generics.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] field/generics.go#L180

exported: exported function NewGenericsString should have comment or be unexported (revive)
Raw output
field/generics.go:180:1: exported: exported function NewGenericsString should have comment or be unexported (revive)
func NewGenericsString[T any](e expr) GenericsString[T] {
^
return GenericsString[T]{GenericsField: NewGenerics[T](e)}
}

// GenericsString string type field
type GenericsString[T any] struct {
GenericsField[T]
Expand Down
29 changes: 15 additions & 14 deletions field/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (field Time) Date() Time {

// DateDiff equal to DATADIFF(self, value)
func (field Time) DateDiff(value time.Time) Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "DATEDIFF(?,?)", Vars: []interface{}{field.RawExpr(), value}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "DATEDIFF(?,?)", Vars: []interface{}{field.RawExpr(), value}}})}
}

// DateFormat equal to DATE_FORMAT(self, value)
func (field Time) DateFormat(value string) String {
return String{GenericsString: GenericsString[string]{GenericsField: GenericsField[string]{expr{e: clause.Expr{SQL: "DATE_FORMAT(?,?)", Vars: []interface{}{field.RawExpr(), value}}}}}}
return String{NewGenericsString[string](expr{e: clause.Expr{SQL: "DATE_FORMAT(?,?)", Vars: []interface{}{field.RawExpr(), value}}})}
}

// Now return result of NOW()
Expand All @@ -69,61 +69,62 @@ func (field Time) CurTime() Time {

// DayName equal to DAYNAME(self)
func (field Time) DayName() String {
return String{GenericsString: GenericsString[string]{GenericsField: GenericsField[string]{expr{e: clause.Expr{SQL: "DAYNAME(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return String{NewGenericsString[string](expr{e: clause.Expr{SQL: "DAYNAME(?)", Vars: []interface{}{field.RawExpr()}}})}

}

// MonthName equal to MONTHNAME(self)
func (field Time) MonthName() String {
return String{GenericsString: GenericsString[string]{GenericsField: GenericsField[string]{expr{e: clause.Expr{SQL: "MONTHNAME(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return String{NewGenericsString[string](expr{e: clause.Expr{SQL: "MONTHNAME(?)", Vars: []interface{}{field.RawExpr()}}})}
}

func (field Time) Year() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "YEAR(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "YEAR(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// Month equal to MONTH(self)
func (field Time) Month() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "MONTH(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "MONTH(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// Day equal to DAY(self)
func (field Time) Day() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "DAY(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "DAY(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// Hour equal to HOUR(self)
func (field Time) Hour() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "HOUR(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "HOUR(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// Minute equal to MINUTE(self)
func (field Time) Minute() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "MINUTE(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "MINUTE(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// Second equal to SECOND(self)
func (field Time) Second() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "SECOND(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "SECOND(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// MicroSecond equal to MICROSECOND(self)
func (field Time) MicroSecond() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "MICROSECOND(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "MICROSECOND(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// DayOfWeek equal to DAYOFWEEK(self)
func (field Time) DayOfWeek() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "DAYOFWEEK(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "DAYOFWEEK(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// DayOfMonth equal to DAYOFMONTH(self)
func (field Time) DayOfMonth() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "DAYOFMONTH(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "DAYOFMONTH(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// DayOfYear equal to DAYOFYEAR(self)
func (field Time) DayOfYear() Int {
return Int{GenericsInt: GenericsInt[int]{GenericsField: GenericsField[int]{expr{e: clause.Expr{SQL: "DAYOFYEAR(?)", Vars: []interface{}{field.RawExpr()}}}}}}
return Int{NewGenericsInt[int](expr{e: clause.Expr{SQL: "DAYOFYEAR(?)", Vars: []interface{}{field.RawExpr()}}})}
}

// FromDays equal to FROM_DAYS(self)
Expand Down
Loading

0 comments on commit b842b51

Please sign in to comment.