dialect/sql: support capturing predicates in selectors

This allows custom predicates mutating the root querying and still respect the AND/OR/NOT semantics
This commit is contained in:
Ariel Mashraki
2023-06-21 19:19:54 +03:00
committed by Ariel Mashraki
parent 4787899669
commit 808edd134d
132 changed files with 475 additions and 2600 deletions

View File

@@ -78,30 +78,13 @@ in the LICENSE file in the root directory of this source tree.
{{- end }}
{{ define "dialect/sql/predicate/and" -}}
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
}
sql.AndPredicates(predicates...)
{{- end }}
{{ define "dialect/sql/predicate/or" -}}
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
}
s.Where(s1.P())
}
sql.OrPredicates(predicates...)
{{- end }}
{{ define "dialect/sql/predicate/not" -}}
func(s *sql.Selector) {
p(s.Not())
}
sql.NotPredicates(p)
{{- end }}