Skip to content

Commit

Permalink
Merge pull request go-gorm#162 from go-gorm/dev
Browse files Browse the repository at this point in the history
feat(field): add method `GroutConcat`
  • Loading branch information
tr1v3r authored Oct 25, 2021
2 parents 35fae03 + 7e02937 commit 69a2b82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions field/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (e expr) appendBuildOpts(opts ...BuildOpt) expr {
}

// ======================== basic function ========================
func (e expr) WithTable(table string) Expr {
e.col.Table = table
return e
}

func (e expr) IsNull() Expr {
return e.setE(clause.Expr{SQL: "? IS NULL", Vars: []interface{}{e.RawExpr()}})
}
Expand Down Expand Up @@ -161,9 +166,8 @@ func (e expr) Null() AssignExpr {
return e.setE(clause.Eq{Column: e.col.Name, Value: nil})
}

func (e expr) WithTable(table string) Expr {
e.col.Table = table
return e
func (e expr) GroutConcat() Expr {
return e.setE(clause.Expr{SQL: "GROUP_CONCAT(?)", Vars: []interface{}{e.RawExpr()}})
}

// ======================== comparison between columns ========================
Expand Down
4 changes: 4 additions & 0 deletions field/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func TestExpr_Build(t *testing.T) {
Expr: field.NewField("", "id").IsNotNull(),
Result: "`id` IS NOT NULL",
},
{
Expr: field.NewField("", "id").GroutConcat(),
Result: "GROUP_CONCAT(`id`)",
},
// ======================== integer ========================
{
Expr: field.NewUint("", "id"),
Expand Down

0 comments on commit 69a2b82

Please sign in to comment.