mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-22 15:41:35 +03:00
9a1c6a7d09
- Implement --arg feature - Refactor sqlbuilder package (now called "render"). - Bug fixes, especially around expressions.
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
|
|
}
|