Passed
Pull Request — master (#1470)
by Tolga
02:39
created

utils.Union   A

Complexity

Conditions 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nop 2
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
package utils
2
3
import (
4
	base "github.com/Permify/permify/pkg/pb/base/v1"
5
)
6
7
// GetRelationTuplesIndexNameAndArgsByFilters - Get index name and arguments by filters
8
func GetRelationTuplesIndexNameAndArgsByFilters(tenantID string, filter *base.TupleFilter) (string, []any) {
9
	if filter.GetEntity().GetType() != "" && filter.GetRelation() != "" {
10
		return "entity-type-and-relation-index", []any{tenantID, filter.GetEntity().GetType(), filter.GetRelation()}
11
	}
12
	if filter.GetEntity().GetType() != "" {
13
		return "entity-type-index", []any{tenantID, filter.GetEntity().GetType()}
14
	}
15
	return "id", nil
16
}
17
18
func GetAttributesIndexNameAndArgsByFilters(tenantID string, filter *base.AttributeFilter) (string, []any) {
19
	if filter.GetEntity().GetType() != "" {
20
		return "entity-type-index", []any{tenantID, filter.GetEntity().GetType()}
21
	}
22
	return "id", nil
23
}
24