MCPcopy Index your code
hub / github.com/coder/coder / convertCall

Function convertCall

coderd/rbac/regosql/compile.go:113–152  ·  view source on GitHub ↗

convertCall converts a function call to a SQL expression.

(cfg ConvertConfig, call ast.Call)

Source from the content-addressed store, hash-verified

111
112// convertCall converts a function call to a SQL expression.
113func convertCall(cfg ConvertConfig, call ast.Call) (sqltypes.Node, error) {
114 if len(call) == 0 {
115 return nil, xerrors.Errorf("empty call")
116 }
117
118 // Operator is the first term
119 op := call[0]
120 var args []*ast.Term
121 if len(call) > 1 {
122 args = call[1:]
123 }
124
125 opString := op.String()
126 // Supported operators.
127 switch op.String() {
128 case "neq", "eq", "equals", "equal":
129 args, err := convertTerms(cfg, args, 2)
130 if err != nil {
131 return nil, xerrors.Errorf("arguments: %w", err)
132 }
133
134 not := false
135 if opString == "neq" || opString == "notequals" || opString == "notequal" {
136 not = true
137 }
138
139 equality := sqltypes.Equality(not, args[0], args[1])
140 return sqltypes.BoolParenthesis(equality), nil
141 case "internal.member_2":
142 args, err := convertTerms(cfg, args, 2)
143 if err != nil {
144 return nil, xerrors.Errorf("arguments: %w", err)
145 }
146
147 member := sqltypes.MemberOf(args[0], args[1])
148 return sqltypes.BoolParenthesis(member), nil
149 default:
150 return nil, xerrors.Errorf("operator %s not supported", op)
151 }
152}
153
154func convertTerms(cfg ConvertConfig, terms []*ast.Term, expected int) ([]sqltypes.Node, error) {
155 if len(terms) != expected {

Callers 2

convertExpressionFunction · 0.85
convertTermFunction · 0.85

Calls 6

EqualityFunction · 0.92
BoolParenthesisFunction · 0.92
MemberOfFunction · 0.92
convertTermsFunction · 0.85
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected