2019-04-29 14:39:48 +02:00
|
|
|
package sqlbuilder
|
|
|
|
|
|
2019-05-30 14:49:36 +02:00
|
|
|
import "fmt"
|
2019-05-29 14:03:38 +02:00
|
|
|
|
2019-04-29 14:39:48 +02:00
|
|
|
// Representation of an escaped literal
|
|
|
|
|
type literalExpression struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
value interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Literal(value interface{}) *literalExpression {
|
|
|
|
|
exp := literalExpression{value: value}
|
|
|
|
|
exp.expressionInterfaceImpl.parent = &exp
|
|
|
|
|
|
|
|
|
|
return &exp
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 14:37:51 +02:00
|
|
|
func (l literalExpression) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
2019-05-08 13:47:01 +02:00
|
|
|
out.insertArgument(l.value)
|
2019-04-29 14:39:48 +02:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2019-05-06 12:42:15 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
type integerLiteralExpression struct {
|
2019-05-06 12:42:15 +02:00
|
|
|
literalExpression
|
2019-05-31 12:59:57 +02:00
|
|
|
integerInterfaceImpl
|
2019-05-06 12:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-01 15:00:37 +02:00
|
|
|
func Int(value int64) IntegerExpression {
|
2019-05-31 12:59:57 +02:00
|
|
|
numLiteral := &integerLiteralExpression{}
|
2019-05-06 12:42:15 +02:00
|
|
|
|
|
|
|
|
numLiteral.literalExpression = *Literal(value)
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
numLiteral.literalExpression.parent = numLiteral
|
|
|
|
|
numLiteral.integerInterfaceImpl.parent = numLiteral
|
2019-05-06 12:42:15 +02:00
|
|
|
|
|
|
|
|
return numLiteral
|
|
|
|
|
}
|
2019-05-29 14:03:38 +02:00
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type boolLiteralExpression struct {
|
|
|
|
|
boolInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
func Bool(value bool) BoolExpression {
|
2019-05-29 14:03:38 +02:00
|
|
|
boolLiteralExpression := boolLiteralExpression{}
|
|
|
|
|
|
|
|
|
|
boolLiteralExpression.literalExpression = *Literal(value)
|
|
|
|
|
boolLiteralExpression.boolInterfaceImpl.parent = &boolLiteralExpression
|
|
|
|
|
|
|
|
|
|
return &boolLiteralExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
2019-05-31 12:59:57 +02:00
|
|
|
type floatLiteral struct {
|
|
|
|
|
floatInterfaceImpl
|
2019-05-29 14:03:38 +02:00
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
func Float(value float64) FloatExpression {
|
|
|
|
|
floatLiteral := floatLiteral{}
|
|
|
|
|
floatLiteral.literalExpression = *Literal(value)
|
2019-05-29 14:03:38 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
floatLiteral.floatInterfaceImpl.parent = &floatLiteral
|
2019-05-29 14:03:38 +02:00
|
|
|
|
2019-05-31 12:59:57 +02:00
|
|
|
return &floatLiteral
|
2019-05-29 14:03:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type stringLiteral struct {
|
|
|
|
|
stringInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func String(value string) stringExpression {
|
|
|
|
|
stringLiteral := stringLiteral{}
|
|
|
|
|
stringLiteral.literalExpression = *Literal(value)
|
|
|
|
|
|
|
|
|
|
stringLiteral.stringInterfaceImpl.parent = &stringLiteral
|
|
|
|
|
|
|
|
|
|
return &stringLiteral
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type timeLiteral struct {
|
|
|
|
|
timeInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-30 14:49:36 +02:00
|
|
|
func Time(hour, minute, second, milliseconds int) timeExpression {
|
2019-05-29 14:03:38 +02:00
|
|
|
timeLiteral := timeLiteral{}
|
2019-05-30 14:49:36 +02:00
|
|
|
timeStr := fmt.Sprintf("%02d:%02d:%02d.%03d", hour, minute, second, milliseconds)
|
|
|
|
|
timeLiteral.literalExpression = *Literal(timeStr)
|
2019-05-29 14:03:38 +02:00
|
|
|
|
|
|
|
|
timeLiteral.timeInterfaceImpl.parent = &timeLiteral
|
|
|
|
|
|
|
|
|
|
return &timeLiteral
|
|
|
|
|
}
|
2019-05-30 14:49:36 +02:00
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type timezLiteral struct {
|
|
|
|
|
timezInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Timez(hour, minute, second, milliseconds, timezone int) timezExpression {
|
|
|
|
|
timezLiteral := timezLiteral{}
|
|
|
|
|
timeStr := fmt.Sprintf("%02d:%02d:%02d.%03d %+03d", hour, minute, second, milliseconds, timezone)
|
|
|
|
|
timezLiteral.literalExpression = *Literal(timeStr)
|
|
|
|
|
|
|
|
|
|
timezLiteral.timezInterfaceImpl.parent = &timezLiteral
|
|
|
|
|
|
|
|
|
|
return &timezLiteral
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type timestampLiteral struct {
|
|
|
|
|
timestampInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Timestamp(year, month, day, hour, minute, second, milliseconds int) TimestampExpression {
|
|
|
|
|
timestampLiteral := timestampLiteral{}
|
|
|
|
|
timeStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, milliseconds)
|
|
|
|
|
timestampLiteral.literalExpression = *Literal(timeStr)
|
|
|
|
|
|
|
|
|
|
timestampLiteral.timestampInterfaceImpl.parent = ×tampLiteral
|
|
|
|
|
|
|
|
|
|
return ×tampLiteral
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type timestampzLiteral struct {
|
|
|
|
|
timestampzInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Timestampz(year, month, day, hour, minute, second, milliseconds, timezone int) TimestampzExpression {
|
|
|
|
|
timestampzLiteral := timestampzLiteral{}
|
|
|
|
|
timeStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d %+04d",
|
|
|
|
|
year, month, day, hour, minute, second, milliseconds, timezone)
|
|
|
|
|
|
|
|
|
|
timestampzLiteral.literalExpression = *Literal(timeStr)
|
|
|
|
|
|
|
|
|
|
timestampzLiteral.timestampzInterfaceImpl.parent = ×tampzLiteral
|
|
|
|
|
|
|
|
|
|
return ×tampzLiteral
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type dateLiteral struct {
|
|
|
|
|
dateInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Date(year, month, day int) DateExpression {
|
|
|
|
|
dateLiteral := dateLiteral{}
|
|
|
|
|
|
|
|
|
|
timeStr := fmt.Sprintf("%04d-%02d-%02d", year, month, day)
|
|
|
|
|
dateLiteral.literalExpression = *Literal(timeStr)
|
|
|
|
|
dateLiteral.dateInterfaceImpl.parent = &dateLiteral
|
|
|
|
|
|
|
|
|
|
return &dateLiteral
|
|
|
|
|
}
|