(cfg ConvertConfig, e *ast.Expr)
| 77 | } |
| 78 | |
| 79 | func 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. |
| 113 | func convertCall(cfg ConvertConfig, call ast.Call) (sqltypes.Node, error) { |
no test coverage detected