Skip to content

Commit 1b1a3c8

Browse files
committed
where exists
1 parent 2465711 commit 1b1a3c8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

orm/query_where.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,23 @@ func (q *Query[T]) generateWhereStr(wheres []where, bindings *[]any) string {
244244
}
245245
return strings.Join(whereStr, " ")
246246
}
247+
248+
func (q *Query[T]) WhereExists(sq *SubQuery) *Query[T] {
249+
q.bindings = append(q.bindings, sq.bindings...)
250+
return q.Where("EXISTS (" + sq.raw + ")")
251+
}
252+
253+
func (q *Query[T]) OrWhereExists(sq *SubQuery) *Query[T] {
254+
q.bindings = append(q.bindings, sq.bindings...)
255+
return q.OrWhere("EXISTS (" + sq.raw + ")")
256+
}
257+
258+
func (q *Query[T]) WhereNotExists(sq *SubQuery) *Query[T] {
259+
q.bindings = append(q.bindings, sq.bindings...)
260+
return q.Where("NOT EXISTS (" + sq.raw + ")")
261+
}
262+
263+
func (q *Query[T]) OrWhereNotExists(sq *SubQuery) *Query[T] {
264+
q.bindings = append(q.bindings, sq.bindings...)
265+
return q.OrWhere("NOT EXISTS (" + sq.raw + ")")
266+
}

0 commit comments

Comments
 (0)