Skip to content

Commit

Permalink
feat: use CommaExpression from gorm/clause
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1v3r committed Aug 2, 2021
1 parent 99517b3 commit a601475
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
19 changes: 2 additions & 17 deletions do.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *DO) Select(columns ...field.Expr) Dao {
if len(columns) == 0 {
return NewDO(s.db.Clauses(clause.Select{}))
}
return NewDO(s.db.Clauses(clause.Select{Expression: CommaExpression{Exprs: toExpression(columns...)}}))
return NewDO(s.db.Clauses(clause.Select{Expression: clause.CommaExpression{Exprs: toExpression(columns...)}}))
}

func (s *DO) Where(conds ...Condition) Dao {
Expand All @@ -161,7 +161,7 @@ func (s *DO) Where(conds ...Condition) Dao {

func (s *DO) Order(columns ...field.Expr) Dao {
Emit(methodOrder)
return NewDO(s.db.Clauses(clause.OrderBy{Expression: CommaExpression{Exprs: toExpression(columns...)}}))
return NewDO(s.db.Clauses(clause.OrderBy{Expression: clause.CommaExpression{Exprs: toExpression(columns...)}}))
}

func (s *DO) Distinct(columns ...field.Expr) Dao {
Expand Down Expand Up @@ -454,21 +454,6 @@ func toInterfaceSlice(value interface{}) []interface{} {
}
}

// ======================== temporary ========================
// CommaExpression comma expression
type CommaExpression struct {
Exprs []clause.Expression
}

func (comma CommaExpression) Build(builder clause.Builder) {
for idx, expr := range comma.Exprs {
if idx > 0 {
_, _ = builder.WriteString(", ")
}
expr.Build(builder)
}
}

// ======================== New Table ========================

// Table return a new table produced by subquery,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.16
require (
golang.org/x/tools v0.1.5
gorm.io/driver/mysql v1.1.1
gorm.io/gorm v1.21.12
gorm.io/gorm v1.21.13-0.20210728110034-7a49629fd1c7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gorm.io/driver/mysql v1.1.1 h1:yr1bpyqiwuSPJ4aGGUX9nu46RHXlF8RASQVb1QQNcvo=
gorm.io/driver/mysql v1.1.1/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYnU=
gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.12 h1:3fQM0Eiz7jcJEhPggHEpoYnsGZqynMzverL77DV40RM=
gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.13-0.20210728110034-7a49629fd1c7 h1:5Mss7ezjcC8lWeoiwwT0+pz51inhy3j0b/nyOpn4SVE=
gorm.io/gorm v1.21.13-0.20210728110034-7a49629fd1c7/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=

0 comments on commit a601475

Please sign in to comment.