2023-04-07 11:00:49 +03:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/neilotoole/sq/libsq/ast"
|
|
|
|
)
|
|
|
|
|
|
|
|
func doOperator(rc *Context, op *ast.OperatorNode) (string, error) {
|
|
|
|
if op == nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2023-06-17 07:54:25 +03:00
|
|
|
text := op.Text()
|
|
|
|
// Check if the dialect overrides the operator.
|
|
|
|
val, ok := rc.Dialect.Ops[text]
|
2023-04-07 11:00:49 +03:00
|
|
|
if !ok {
|
2023-06-17 07:54:25 +03:00
|
|
|
val = text
|
2023-04-07 11:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
rhs := ast.NodeNextSibling(op)
|
2023-06-17 07:54:25 +03:00
|
|
|
if lit, ok := ast.NodeUnwrap[*ast.LiteralNode](rhs); ok && lit.Text() == "null" {
|
2023-04-07 11:00:49 +03:00
|
|
|
switch op.Text() {
|
|
|
|
case "==":
|
|
|
|
val = "IS"
|
|
|
|
case "!=":
|
|
|
|
val = "IS NOT"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-17 07:54:25 +03:00
|
|
|
// By default, just return the operator unchanged.
|
2023-04-07 11:00:49 +03:00
|
|
|
return val, nil
|
|
|
|
}
|