Skip to content

Commit

Permalink
implement gen.Exists method (go-gorm#868)
Browse files Browse the repository at this point in the history
* feat: implement gen.Exists method

* feat: remove verbose generated method
  • Loading branch information
tr1v3r authored and jeepc committed Jul 3, 2023
1 parent c62bce6 commit 3ee5eb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 6 additions & 0 deletions do.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ func Table(subQueries ...SubQuery) Dao {
}
}

// Exists EXISTS expression
// SELECT * FROM table WHERE EXISTS (SELECT NAME FROM users WHERE id = 1)
func Exists(subQuery SubQuery) Condition {
return field.CompareSubQuery(field.ExistsOp, nil, subQuery.underlyingDB())
}

// ======================== sub query method ========================

// Columns columns array
Expand Down
4 changes: 0 additions & 4 deletions internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func ({{.S}} {{.QueryStructName}}Do) Where(conds ...gen.Condition) {{.ReturnObje
return {{.S}}.withDO({{.S}}.DO.Where(conds...))
}
func ({{.S}} {{.QueryStructName}}Do) Exists(subquery interface{UnderlyingDB() *gorm.DB}) {{.ReturnObject}} {
return {{.S}}.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func ({{.S}} {{.QueryStructName}}Do) Order(conds ...field.Expr) {{.ReturnObject}} {
return {{.S}}.withDO({{.S}}.DO.Order(conds...))
}
Expand Down

0 comments on commit 3ee5eb8

Please sign in to comment.