2019-06-02 18:12:44 +02:00
|
|
|
package sqlbuilder
|
|
|
|
|
|
|
|
|
|
type cast struct {
|
2019-06-04 12:10:23 +02:00
|
|
|
Expression
|
2019-06-03 17:05:29 +02:00
|
|
|
castType string
|
2019-06-02 18:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newCast(expression Expression, castType string) *cast {
|
2019-06-03 17:05:29 +02:00
|
|
|
return &cast{
|
2019-06-04 12:10:23 +02:00
|
|
|
Expression: expression,
|
2019-06-02 18:12:44 +02:00
|
|
|
castType: castType,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *cast) serialize(statement statementType, out *queryData, options ...serializeOption) error {
|
2019-06-04 12:10:23 +02:00
|
|
|
err := b.Expression.serialize(statement, out, options...)
|
2019-06-02 18:12:44 +02:00
|
|
|
out.writeString("::" + b.castType)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type boolCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
boolInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newBoolCast(expression Expression) BoolExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
boolCast := &boolCast{cast: *newCast(expression, "boolean")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
boolCast.boolInterfaceImpl.parent = boolCast
|
|
|
|
|
boolCast.expressionInterfaceImpl.parent = boolCast
|
|
|
|
|
|
|
|
|
|
return boolCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type integerCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
integerInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-07 14:23:14 +02:00
|
|
|
func newIntegerCast(expression Expression, intType string) IntegerExpression {
|
|
|
|
|
integerCast := &integerCast{cast: *newCast(expression, intType)}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
integerCast.integerInterfaceImpl.parent = integerCast
|
|
|
|
|
integerCast.expressionInterfaceImpl.parent = integerCast
|
|
|
|
|
|
|
|
|
|
return integerCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type floatCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
floatInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-07 14:23:14 +02:00
|
|
|
func newFloatCast(expression Expression, floatType string) FloatExpression {
|
|
|
|
|
floatCast := &floatCast{cast: *newCast(expression, floatType)}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
floatCast.floatInterfaceImpl.parent = floatCast
|
|
|
|
|
floatCast.expressionInterfaceImpl.parent = floatCast
|
|
|
|
|
|
|
|
|
|
return floatCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type textCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
stringInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTextCast(expression Expression) StringExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
textCast := &textCast{cast: *newCast(expression, "text")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
textCast.stringInterfaceImpl.parent = textCast
|
|
|
|
|
textCast.expressionInterfaceImpl.parent = textCast
|
|
|
|
|
|
|
|
|
|
return textCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type dateCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
dateInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newDateCast(expression Expression) DateExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
dateCast := &dateCast{cast: *newCast(expression, "date")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
dateCast.dateInterfaceImpl.parent = dateCast
|
|
|
|
|
dateCast.expressionInterfaceImpl.parent = dateCast
|
|
|
|
|
|
|
|
|
|
return dateCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timeCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
timeInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimeCast(expression Expression) TimeExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
timeCast := &timeCast{cast: *newCast(expression, "time without time zone")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
timeCast.timeInterfaceImpl.parent = timeCast
|
|
|
|
|
timeCast.expressionInterfaceImpl.parent = timeCast
|
|
|
|
|
|
|
|
|
|
return timeCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timezCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
timezInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimezCast(expression Expression) TimezExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
timezCast := &timezCast{cast: *newCast(expression, "time with time zone")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
timezCast.timezInterfaceImpl.parent = timezCast
|
|
|
|
|
timezCast.expressionInterfaceImpl.parent = timezCast
|
|
|
|
|
|
|
|
|
|
return timezCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timestampCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
timestampInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimestampCast(expression Expression) TimestampExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
timestampCast := ×tampCast{cast: *newCast(expression, "timestamp without time zone")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
timestampCast.timestampInterfaceImpl.parent = timestampCast
|
|
|
|
|
timestampCast.expressionInterfaceImpl.parent = timestampCast
|
|
|
|
|
|
|
|
|
|
return timestampCast
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type timestampzCast struct {
|
|
|
|
|
expressionInterfaceImpl
|
|
|
|
|
timestampzInterfaceImpl
|
|
|
|
|
cast
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 12:10:23 +02:00
|
|
|
func newTimestampzCast(expression Expression) TimestampzExpression {
|
2019-06-03 17:05:29 +02:00
|
|
|
timestampzCast := ×tampzCast{cast: *newCast(expression, "timestamp with time zone")}
|
2019-06-02 18:12:44 +02:00
|
|
|
|
|
|
|
|
timestampzCast.timestampzInterfaceImpl.parent = timestampzCast
|
|
|
|
|
timestampzCast.expressionInterfaceImpl.parent = timestampzCast
|
|
|
|
|
|
|
|
|
|
return timestampzCast
|
|
|
|
|
}
|