-
Notifications
You must be signed in to change notification settings - Fork 0
/
cond_exists.go
49 lines (40 loc) · 1013 Bytes
/
cond_exists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2022 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package builder
import (
"errors"
"io"
)
type condExists struct {
subQuery *Builder
}
var _ Cond = condExists{}
// Exists returns Cond via condition
func Exists(subQuery *Builder) Cond {
return &condExists{
subQuery: subQuery,
}
}
func (condExists condExists) WriteTo(w Writer) error {
if !condExists.IsValid() {
return errors.New("exists condition is nov valid")
}
if _, err := io.WriteString(w, "EXISTS ("); err != nil {
return err
}
if err := condExists.subQuery.WriteTo(w); err != nil {
return err
}
_, err := io.WriteString(w, ")")
return err
}
func (condExists condExists) And(conds ...Cond) Cond {
return And(condExists, And(conds...))
}
func (condExists condExists) Or(conds ...Cond) Cond {
return Or(condExists, Or(conds...))
}
func (condExists condExists) IsValid() bool {
return condExists.subQuery != nil
}