mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-24 08:36:43 +03:00
e93f462fff
Implement explicit `where()` clause.
32 lines
573 B
Go
32 lines
573 B
Go
package render
|
|
|
|
import (
|
|
"github.com/neilotoole/sq/libsq/ast"
|
|
)
|
|
|
|
func doOperator(rc *Context, op *ast.OperatorNode) (string, error) {
|
|
if op == nil {
|
|
return "", nil
|
|
}
|
|
|
|
text := op.Text()
|
|
// Check if the dialect overrides the operator.
|
|
val, ok := rc.Dialect.Ops[text]
|
|
if !ok {
|
|
val = text
|
|
}
|
|
|
|
rhs := ast.NodeNextSibling(op)
|
|
if lit, ok := ast.NodeUnwrap[*ast.LiteralNode](rhs); ok && lit.Text() == "null" {
|
|
switch op.Text() {
|
|
case "==":
|
|
val = "IS"
|
|
case "!=":
|
|
val = "IS NOT"
|
|
}
|
|
}
|
|
|
|
// By default, just return the operator unchanged.
|
|
return val, nil
|
|
}
|