2019-04-29 14:39:48 +02:00
|
|
|
package sqlbuilder
|
|
|
|
|
|
2019-05-29 14:03:38 +02:00
|
|
|
import "time"
|
|
|
|
|
|
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-08 13:47:01 +02:00
|
|
|
func (l literalExpression) serialize(statement statementType, out *queryData) error {
|
|
|
|
|
out.insertArgument(l.value)
|
2019-04-29 14:39:48 +02:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2019-05-06 12:42:15 +02:00
|
|
|
|
|
|
|
|
type numLiteralExpression struct {
|
|
|
|
|
literalExpression
|
|
|
|
|
numericInterfaceImpl
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 14:03:38 +02:00
|
|
|
func Int(value int) numericExpression {
|
2019-05-06 12:42:15 +02:00
|
|
|
numLiteral := &numLiteralExpression{}
|
|
|
|
|
|
|
|
|
|
numLiteral.literalExpression = *Literal(value)
|
|
|
|
|
numLiteral.literalExpression.parent = numLiteral
|
|
|
|
|
|
|
|
|
|
numLiteral.numericInterfaceImpl.parent = numLiteral
|
|
|
|
|
|
|
|
|
|
return numLiteral
|
|
|
|
|
}
|
2019-05-29 14:03:38 +02:00
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type boolLiteralExpression struct {
|
|
|
|
|
boolInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bool(value bool) boolExpression {
|
|
|
|
|
boolLiteralExpression := boolLiteralExpression{}
|
|
|
|
|
|
|
|
|
|
boolLiteralExpression.literalExpression = *Literal(value)
|
|
|
|
|
boolLiteralExpression.boolInterfaceImpl.parent = &boolLiteralExpression
|
|
|
|
|
|
|
|
|
|
return &boolLiteralExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
type numericLiteral struct {
|
|
|
|
|
numericInterfaceImpl
|
|
|
|
|
literalExpression
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Float(value float64) numericExpression {
|
|
|
|
|
numericLiteral := numericLiteral{}
|
|
|
|
|
numericLiteral.literalExpression = *Literal(value)
|
|
|
|
|
|
|
|
|
|
numericLiteral.numericInterfaceImpl.parent = &numericLiteral
|
|
|
|
|
|
|
|
|
|
return &numericLiteral
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------//
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Time(value time.Time) timeExpression {
|
|
|
|
|
timeLiteral := timeLiteral{}
|
|
|
|
|
timeLiteral.literalExpression = *Literal(value)
|
|
|
|
|
|
|
|
|
|
timeLiteral.timeInterfaceImpl.parent = &timeLiteral
|
|
|
|
|
|
|
|
|
|
return &timeLiteral
|
|
|
|
|
}
|