mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-30 11:46:08 +03:00
32 lines
600 B
Go
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
|
||
|
}
|