-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcond_not_exists.go
49 lines (40 loc) · 1.05 KB
/
cond_not_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 condNotExists struct {
subQuery *Builder
}
var _ Cond = condNotExists{}
// NotExists returns Cond via condition
func NotExists(subQuery *Builder) Cond {
return &condNotExists{
subQuery: subQuery,
}
}
func (condNotExists condNotExists) WriteTo(w Writer) error {
if !condNotExists.IsValid() {
return errors.New("exists condition is nov valid")
}
if _, err := io.WriteString(w, "NOT EXISTS ("); err != nil {
return err
}
if err := condNotExists.subQuery.WriteTo(w); err != nil {
return err
}
_, err := io.WriteString(w, ")")
return err
}
func (condNotExists condNotExists) And(conds ...Cond) Cond {
return And(condNotExists, And(conds...))
}
func (condNotExists condNotExists) Or(conds ...Cond) Cond {
return Or(condNotExists, Or(conds...))
}
func (condNotExists condNotExists) IsValid() bool {
return condNotExists.subQuery != nil
}