-
Notifications
You must be signed in to change notification settings - Fork 15
/
key_column_slice.go
71 lines (60 loc) · 1.47 KB
/
key_column_slice.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package plugin
import (
"strings"
"github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto"
)
type KeyColumnSlice []*KeyColumn
func (k KeyColumnSlice) String() string {
return strings.Join(k.StringSlice(), "\n")
}
// StringSlice converts a KeyColumnSlice to a slice of strings
func (k KeyColumnSlice) StringSlice() []string {
strs := make([]string, len(k))
for i, c := range k {
strs[i] = c.String()
}
return strs
}
// ToProtobuf converts the KeyColumnSlice to a slice of protobuf KeyColumns
func (k KeyColumnSlice) ToProtobuf() []*proto.KeyColumn {
var res = make([]*proto.KeyColumn, len(k))
for i, col := range k {
res[i] = col.ToProtobuf()
}
return res
}
// AllEquals returns whether all KeyColumns only use equals operators
func (k KeyColumnSlice) AllEquals() bool {
for _, col := range k {
if !col.SingleEqualsQual() {
return false
}
}
return true
}
// IsAnyOf returns whether all key columns have Require == AnyOf
func (k KeyColumnSlice) IsAnyOf() bool {
for _, kc := range k {
if kc.Require != AnyOf {
return false
}
}
return true
}
// Validate validates all child columns
func (k KeyColumnSlice) Validate() []string {
var res []string
for _, col := range k {
res = append(res, col.Validate()...)
}
return res
}
// Find looks for a key column with the given name and returns it if found
func (k *KeyColumnSlice) Find(name string) *KeyColumn {
for _, keyColumn := range *k {
if keyColumn.Name == name {
return keyColumn
}
}
return nil
}