-
Notifications
You must be signed in to change notification settings - Fork 15
/
qual.go
42 lines (34 loc) · 875 Bytes
/
qual.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
package quals
import (
"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
)
// Qual is a struct which represents a database qual in a more easily digestible form that proto.Qual
type Qual struct {
Column string
Operator string
Value *proto.QualValue
}
func NewQual(q *proto.Qual) *Qual {
return &Qual{
Column: q.FieldName,
Operator: q.GetStringValue(),
Value: q.Value,
}
}
func (q *Qual) Equals(other *Qual) bool {
return q.Column == other.Column && q.Operator == other.Operator && q.Value.String() == other.Value.String()
}
type QualSlice []*Qual
func (s QualSlice) SingleEqualsQual() bool {
return len(s) == 1 && s[0].Operator == "="
}
func (s QualSlice) Contains(other *Qual) bool {
alreadyExists := false
for _, existingQual := range s {
if existingQual.Equals(other) {
alreadyExists = true
break
}
}
return alreadyExists
}