2021-10-21 13:39:24 +02:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-14 17:04:09 +00:00
|
|
|
"source.gleipnir.technology/Gleipnir/jet/v2/internal/jet"
|
2021-10-21 13:39:24 +02:00
|
|
|
)
|
|
|
|
|
|
2026-02-02 13:21:35 +01:00
|
|
|
// CAST function converts an expr (of any type) into later specified datatype.
|
2024-11-01 12:30:37 +01:00
|
|
|
func CAST(expr Expression) *cast {
|
2026-02-02 13:21:35 +01:00
|
|
|
return &cast{
|
|
|
|
|
expr: expr,
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-01 12:30:37 +01:00
|
|
|
|
2026-02-02 13:21:35 +01:00
|
|
|
type cast struct {
|
|
|
|
|
expr Expression
|
2021-10-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS casts expressions to castType
|
2024-11-01 12:30:37 +01:00
|
|
|
func (c *cast) AS(castType string) Expression {
|
2026-02-02 13:21:35 +01:00
|
|
|
return jet.AtomicCustomExpression(Token("CAST("), c.expr, Token("AS "+castType+")"))
|
2021-10-21 13:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS_TEXT cast expression to TEXT type
|
2024-11-01 12:30:37 +01:00
|
|
|
func (c *cast) AS_TEXT() StringExpression {
|
2021-10-21 13:39:24 +02:00
|
|
|
return StringExp(c.AS("TEXT"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS_NUMERIC cast expression to NUMERIC type
|
2024-11-01 12:30:37 +01:00
|
|
|
func (c *cast) AS_NUMERIC() FloatExpression {
|
2021-10-21 13:39:24 +02:00
|
|
|
return FloatExp(c.AS("NUMERIC"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS_INTEGER cast expression to INTEGER type
|
2024-11-01 12:30:37 +01:00
|
|
|
func (c *cast) AS_INTEGER() IntegerExpression {
|
2021-10-21 13:39:24 +02:00
|
|
|
return IntExp(c.AS("INTEGER"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS_REAL cast expression to REAL type
|
2024-11-01 12:30:37 +01:00
|
|
|
func (c *cast) AS_REAL() FloatExpression {
|
2021-10-21 13:39:24 +02:00
|
|
|
return FloatExp(c.AS("REAL"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AS_BLOB cast expression to BLOB type
|
2025-02-28 18:23:15 +01:00
|
|
|
func (c *cast) AS_BLOB() BlobExpression {
|
|
|
|
|
return BlobExp(c.AS("BLOB"))
|
2021-10-21 13:39:24 +02:00
|
|
|
}
|