mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-18 21:52:28 +03:00
26 lines
622 B
Go
26 lines
622 B
Go
|
package render
|
||
|
|
||
|
import (
|
||
|
"github.com/neilotoole/sq/libsq/ast"
|
||
|
"github.com/neilotoole/sq/libsq/core/stringz"
|
||
|
)
|
||
|
|
||
|
// Literal implement FragmentBuilder.
|
||
|
func doLiteral(_ *Context, lit *ast.LiteralNode) (string, error) {
|
||
|
switch lit.LiteralType() {
|
||
|
case ast.LiteralNull:
|
||
|
return "NULL", nil
|
||
|
case ast.LiteralNaturalNumber, ast.LiteralAnyNumber:
|
||
|
return lit.Text(), nil
|
||
|
case ast.LiteralString:
|
||
|
text, _, err := unquoteLiteral(lit.Text())
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
return stringz.SingleQuote(text), nil
|
||
|
default:
|
||
|
// Should never happen.
|
||
|
panic("unknown literal type: " + string(lit.LiteralType()))
|
||
|
}
|
||
|
}
|