jet/postgres/literal.go

131 lines
4.3 KiB
Go
Raw Normal View History

2019-08-03 14:10:47 +02:00
package postgres
import (
"time"
"github.com/go-jet/jet/v2/internal/jet"
)
2019-08-03 14:10:47 +02:00
2021-12-29 19:07:59 +01:00
// Bool is boolean literal constructor
func Bool(value bool) BoolExpression {
return CAST(jet.Bool(value)).AS_BOOL()
}
2019-08-17 14:49:35 +02:00
2021-02-22 13:58:28 -05:00
// Int is constructor for 64 bit signed integer expressions literals.
2019-08-03 14:10:47 +02:00
var Int = jet.Int
2019-08-17 14:49:35 +02:00
2021-02-22 13:58:28 -05:00
// Int8 is constructor for 8 bit signed integer expressions literals.
func Int8(value int8) IntegerExpression {
return CAST(jet.Int8(value)).AS_SMALLINT()
}
2021-02-22 13:58:28 -05:00
// Int16 is constructor for 16 bit signed integer expressions literals.
func Int16(value int16) IntegerExpression {
return CAST(jet.Int16(value)).AS_SMALLINT()
}
2021-02-22 13:58:28 -05:00
// Int32 is constructor for 32 bit signed integer expressions literals.
func Int32(value int32) IntegerExpression {
return CAST(jet.Int32(value)).AS_INTEGER()
}
2021-02-22 13:58:28 -05:00
// Int64 is constructor for 64 bit signed integer expressions literals.
func Int64(value int64) IntegerExpression {
return CAST(jet.Int(value)).AS_BIGINT()
}
2021-02-22 13:58:28 -05:00
// Uint8 is constructor for 8 bit unsigned integer expressions literals.
func Uint8(value uint8) IntegerExpression {
return CAST(jet.Uint8(value)).AS_SMALLINT()
}
2021-02-22 13:58:28 -05:00
// Uint16 is constructor for 16 bit unsigned integer expressions literals.
func Uint16(value uint16) IntegerExpression {
return CAST(jet.Uint16(value)).AS_INTEGER()
}
2021-02-22 13:58:28 -05:00
// Uint32 is constructor for 32 bit unsigned integer expressions literals.
func Uint32(value uint32) IntegerExpression {
return CAST(jet.Uint32(value)).AS_BIGINT()
}
2021-02-22 13:58:28 -05:00
// Uint64 is constructor for 64 bit unsigned integer expressions literals.
func Uint64(value uint64) IntegerExpression {
return CAST(jet.Uint64(value)).AS_BIGINT()
}
2021-02-22 13:58:28 -05:00
2019-08-17 14:49:35 +02:00
// Float creates new float literal expression
2019-08-03 14:10:47 +02:00
var Float = jet.Float
2019-08-17 14:49:35 +02:00
// Decimal creates new float literal expression
var Decimal = jet.Decimal
2019-08-17 14:49:35 +02:00
// String creates new string literal expression
2022-05-05 13:01:42 +02:00
func String(value string) StringExpression {
return CAST(jet.String(value)).AS_TEXT()
}
// UUID is a helper function to create string literal expression from uuid object
// value can be any uuid type with a String method
var UUID = jet.UUID
// Bytea creates new bytea literal expression
2022-05-16 11:51:47 +02:00
func Bytea(value interface{}) StringExpression {
switch value.(type) {
case string, []byte:
default:
panic("Bytea parameter value has to be of the type string or []byte")
}
return CAST(jet.Literal(value)).AS_BYTEA()
}
2019-08-17 14:49:35 +02:00
// Date creates new date literal expression
2022-05-16 11:51:47 +02:00
func Date(year int, month time.Month, day int) DateExpression {
2019-08-03 14:10:47 +02:00
return CAST(jet.Date(year, month, day)).AS_DATE()
}
2019-08-17 14:49:35 +02:00
// DateT creates new date literal expression from time.Time object
2022-05-16 11:51:47 +02:00
func DateT(t time.Time) DateExpression {
return CAST(jet.DateT(t)).AS_DATE()
}
2019-08-17 14:49:35 +02:00
// Time creates new time literal expression
2022-05-16 11:51:47 +02:00
func Time(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression {
2019-08-13 10:16:26 +02:00
return CAST(jet.Time(hour, minute, second, nanoseconds...)).AS_TIME()
2019-08-03 14:10:47 +02:00
}
2019-08-17 14:49:35 +02:00
// TimeT creates new time literal expression from time.Time object
2022-05-16 11:51:47 +02:00
func TimeT(t time.Time) TimeExpression {
return CAST(jet.TimeT(t)).AS_TIME()
}
2019-08-17 14:49:35 +02:00
// Timez creates new time with time zone literal expression
2022-05-16 11:51:47 +02:00
func Timez(hour, minute, second int, milliseconds time.Duration, timezone string) TimezExpression {
2019-08-03 14:10:47 +02:00
return CAST(jet.Timez(hour, minute, second, milliseconds, timezone)).AS_TIMEZ()
}
2019-08-17 14:49:35 +02:00
// TimezT creates new time with time zone literal expression from time.Time object
2022-05-16 11:51:47 +02:00
func TimezT(t time.Time) TimezExpression {
return CAST(jet.TimezT(t)).AS_TIMEZ()
}
2019-08-17 14:49:35 +02:00
// Timestamp creates new timestamp literal expression
2022-05-16 11:51:47 +02:00
func Timestamp(year int, month time.Month, day, hour, minute, second int, milliseconds ...time.Duration) TimestampExpression {
2019-08-13 10:16:26 +02:00
return CAST(jet.Timestamp(year, month, day, hour, minute, second, milliseconds...)).AS_TIMESTAMP()
2019-08-03 14:10:47 +02:00
}
2019-08-17 14:49:35 +02:00
// TimestampT creates new timestamp literal expression from time.Time object
2022-05-16 11:51:47 +02:00
func TimestampT(t time.Time) TimestampExpression {
2019-08-17 14:49:35 +02:00
return CAST(jet.TimestampT(t)).AS_TIMESTAMP()
}
2019-08-17 14:49:35 +02:00
// Timestampz creates new timestamp with time zone literal expression
2022-05-16 11:51:47 +02:00
func Timestampz(year int, month time.Month, day, hour, minute, second int, milliseconds time.Duration, timezone string) TimestampzExpression {
2019-08-03 14:10:47 +02:00
return CAST(jet.Timestampz(year, month, day, hour, minute, second, milliseconds, timezone)).AS_TIMESTAMPZ()
}
2019-08-17 14:49:35 +02:00
// TimestampzT creates new timestamp literal expression from time.Time object
2022-05-16 11:51:47 +02:00
func TimestampzT(t time.Time) TimestampzExpression {
return CAST(jet.TimestampzT(t)).AS_TIMESTAMPZ()
}