mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
2ba633fc2a
* Fixed space issues with expressions * Alias can now be an arbitrary string * Alias can now be an arbitrary string (fixed) * Alias now automatically applied to expressions * Ignore .run * Fixed issue with TestRun not logging correctly to testing.T * Fiddling with sqlite3 temp file closing * Re-enable tests
44 lines
742 B
Go
44 lines
742 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.
|
|
if operatorHasSpace(val) {
|
|
val = " " + val + " "
|
|
}
|
|
|
|
return val, nil
|
|
}
|
|
|
|
func operatorHasSpace(op string) bool {
|
|
switch op {
|
|
case "-", "+", "*", "/":
|
|
return false
|
|
}
|
|
return true
|
|
}
|