• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Permify / permify / 6428700044

06 Oct 2023 07:20AM UTC coverage: 73.003%. Remained the same
6428700044

Pull #741

github

tolgaOzen
feat: implement GitHub Action for docs deployment
Pull Request #741: feat: implement GitHub Action for docs deployment

4605 of 6308 relevant lines covered (73.0%)

70.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.49
/internal/storage/postgres/utils/filter.go
1
package utils
2

3
import (
4
        "github.com/Masterminds/squirrel"
5

6
        base "github.com/Permify/permify/pkg/pb/base/v1"
7
)
8

9
// TuplesFilterQueryForSelectBuilder -
10
func TuplesFilterQueryForSelectBuilder(sl squirrel.SelectBuilder, filter *base.TupleFilter) squirrel.SelectBuilder {
4✔
11
        eq := squirrel.Eq{}
4✔
12

4✔
13
        if filter.GetEntity().GetType() != "" {
6✔
14
                eq["entity_type"] = filter.GetEntity().GetType()
2✔
15
        }
2✔
16

17
        if len(filter.GetEntity().GetIds()) > 0 {
6✔
18
                eq["entity_id"] = filter.GetEntity().GetIds()
2✔
19
        }
2✔
20

21
        if filter.GetRelation() != "" {
5✔
22
                eq["relation"] = filter.GetRelation()
1✔
23
        }
1✔
24

25
        if filter.GetSubject().GetType() != "" {
6✔
26
                eq["subject_type"] = filter.GetSubject().GetType()
2✔
27
        }
2✔
28

29
        if len(filter.GetSubject().GetIds()) > 0 {
6✔
30
                eq["subject_id"] = filter.GetSubject().GetIds()
2✔
31
        }
2✔
32

33
        if filter.GetSubject().GetRelation() != "" {
5✔
34
                eq["subject_relation"] = filter.GetSubject().GetRelation()
1✔
35
        }
1✔
36

37
        // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
38
        // This ensures we don't accidentally update every row in the table.
39
        if len(eq) == 0 {
6✔
40
                return sl
2✔
41
        }
2✔
42

43
        return sl.Where(eq)
2✔
44
}
45

46
// AttributesFilterQueryForSelectBuilder -
47
func AttributesFilterQueryForSelectBuilder(sl squirrel.SelectBuilder, filter *base.AttributeFilter) squirrel.SelectBuilder {
×
48
        eq := squirrel.Eq{}
×
49

×
50
        if filter.GetEntity().GetType() != "" {
×
51
                eq["entity_type"] = filter.GetEntity().GetType()
×
52
        }
×
53

54
        if len(filter.GetEntity().GetIds()) > 0 {
×
55
                eq["entity_id"] = filter.GetEntity().GetIds()
×
56
        }
×
57

58
        if len(filter.GetAttributes()) > 0 {
×
59
                eq["attribute"] = filter.GetAttributes()
×
60
        }
×
61

62
        // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
63
        // This ensures we don't accidentally update every row in the table.
64
        if len(eq) == 0 {
×
65
                return sl
×
66
        }
×
67

68
        return sl.Where(eq)
×
69
}
70

71
// TuplesFilterQueryForUpdateBuilder -
72
func TuplesFilterQueryForUpdateBuilder(sl squirrel.UpdateBuilder, filter *base.TupleFilter) squirrel.UpdateBuilder {
×
73
        eq := squirrel.Eq{}
×
74

×
75
        if filter.GetEntity().GetType() != "" {
×
76
                eq["entity_type"] = filter.GetEntity().GetType()
×
77
        }
×
78

79
        if len(filter.GetEntity().GetIds()) > 0 {
×
80
                eq["entity_id"] = filter.GetEntity().GetIds()
×
81
        }
×
82

83
        if filter.GetRelation() != "" {
×
84
                eq["relation"] = filter.GetRelation()
×
85
        }
×
86

87
        if filter.GetSubject().GetType() != "" {
×
88
                eq["subject_type"] = filter.GetSubject().GetType()
×
89
        }
×
90

91
        if len(filter.GetSubject().GetIds()) > 0 {
×
92
                eq["subject_id"] = filter.GetSubject().GetIds()
×
93
        }
×
94

95
        if filter.GetSubject().GetRelation() != "" {
×
96
                eq["subject_relation"] = filter.GetSubject().GetRelation()
×
97
        }
×
98

99
        // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
100
        // This ensures we don't accidentally update every row in the table.
101
        if len(eq) == 0 {
×
102
                return sl
×
103
        }
×
104

105
        return sl.Where(eq)
×
106
}
107

108
// AttributesFilterQueryForUpdateBuilder -
109
func AttributesFilterQueryForUpdateBuilder(sl squirrel.UpdateBuilder, filter *base.AttributeFilter) squirrel.UpdateBuilder {
×
110
        eq := squirrel.Eq{}
×
111

×
112
        if filter.GetEntity().GetType() != "" {
×
113
                eq["entity_type"] = filter.GetEntity().GetType()
×
114
        }
×
115

116
        if len(filter.GetEntity().GetIds()) > 0 {
×
117
                eq["entity_id"] = filter.GetEntity().GetIds()
×
118
        }
×
119

120
        if len(filter.GetAttributes()) > 0 {
×
121
                eq["attribute"] = filter.GetAttributes()
×
122
        }
×
123

124
        // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
125
        // This ensures we don't accidentally update every row in the table.
126
        if len(eq) == 0 {
×
127
                return sl
×
128
        }
×
129

130
        return sl.Where(eq)
×
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc