sq/libsq/ast/render/operator.go
Neil O'Toole 9a1c6a7d09
Feature/173 args (#183)
- Implement --arg feature
- Refactor sqlbuilder package (now called "render").
- Bug fixes, especially around expressions.
2023-04-07 02:00:49 -06:00

32 lines
600 B
Go

package render
import (
"github.com/neilotoole/sq/libsq/ast"
"github.com/neilotoole/sq/libsq/core/errz"
)
func doOperator(rc *Context, op *ast.OperatorNode) (string, error) {
if op == nil {
return "", nil
}
val, ok := rc.Dialect.Ops[op.Text()]
if !ok {
return "", errz.Errorf("invalid operator: %s", op.Text())
}
rhs := ast.NodeNextSibling(op)
if lit, ok := rhs.(*ast.LiteralNode); ok && lit.Text() == "null" {
switch op.Text() {
case "==":
val = "IS"
case "!=":
val = "IS NOT"
default:
return "", errz.Errorf("invalid operator for null")
}
}
return val, nil
}