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

Function convertExpression

coderd/rbac/regosql/compile.go:79–110  ·  view source on GitHub ↗
(cfg ConvertConfig, e *ast.Expr)

Source from the content-addressed store, hash-verified

77}
78
79func convertExpression(cfg ConvertConfig, e *ast.Expr) (sqltypes.BooleanNode, error) {
80 if e.IsCall() {
81 //nolint:forcetypeassert
82 n, err := convertCall(cfg, e.Terms.([]*ast.Term))
83 if err != nil {
84 return nil, xerrors.Errorf("call: %w", err)
85 }
86
87 boolN, ok := n.(sqltypes.BooleanNode)
88 if !ok {
89 return nil, xerrors.Errorf("call %q: not a boolean expression", e.String())
90 }
91 return boolN, nil
92 }
93
94 // If it's not a call, it is a single term
95 if term, ok := e.Terms.(*ast.Term); ok {
96 ty, err := convertTerm(cfg, term)
97 if err != nil {
98 return nil, xerrors.Errorf("convert term %s: %w", term.String(), err)
99 }
100
101 tyBool, ok := ty.(sqltypes.BooleanNode)
102 if !ok {
103 return nil, xerrors.Errorf("convert term %s is not a boolean: %w", term.String(), err)
104 }
105
106 return tyBool, nil
107 }
108
109 return nil, xerrors.Errorf("expression %s not supported", e.String())
110}
111
112// convertCall converts a function call to a SQL expression.
113func convertCall(cfg ConvertConfig, call ast.Call) (sqltypes.Node, error) {

Callers 1

convertQueryFunction · 0.85

Calls 4

convertCallFunction · 0.85
convertTermFunction · 0.85
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected