From e1b2ee26d7acfee379995213ae4257597ab3eff7 Mon Sep 17 00:00:00 2001 From: r1v3r Date: Wed, 7 Jun 2023 17:18:32 +0800 Subject: [PATCH] implement gen.Exists method (#868) * feat: implement gen.Exists method * feat: remove verbose generated method --- do.go | 6 ++++++ internal/template/method.go | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/do.go b/do.go index 99ea4dcc..05857a34 100644 --- a/do.go +++ b/do.go @@ -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 diff --git a/internal/template/method.go b/internal/template/method.go index a562d0e0..bb02af52 100644 --- a/internal/template/method.go +++ b/internal/template/method.go @@ -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...)) }