2019-08-06 10:29:04 +02:00
|
|
|
package mysql
|
|
|
|
|
|
2019-08-06 11:41:45 +02:00
|
|
|
import (
|
2024-02-20 23:56:11 +05:30
|
|
|
"fmt"
|
2019-08-06 11:41:45 +02:00
|
|
|
"time"
|
2024-02-20 23:56:11 +05:30
|
|
|
|
|
|
|
|
"github.com/go-jet/jet/v2/internal/jet"
|
2019-08-06 11:41:45 +02:00
|
|
|
)
|
2019-08-06 10:29:04 +02:00
|
|
|
|
2019-08-17 10:43:16 +02:00
|
|
|
// Keywords
|
|
|
|
|
var (
|
|
|
|
|
STAR = jet.STAR
|
|
|
|
|
NULL = jet.NULL
|
|
|
|
|
DEFAULT = jet.DEFAULT
|
|
|
|
|
)
|
2019-08-11 12:13:59 +02:00
|
|
|
|
2019-08-17 10:43:16 +02:00
|
|
|
// Bool creates new bool literal expression
|
2019-08-06 10:29:04 +02:00
|
|
|
var Bool = jet.Bool
|
2019-08-17 10:43:16 +02:00
|
|
|
|
2021-02-22 13:58:28 -05:00
|
|
|
// Int is constructor for 64 bit signed integer expressions literals.
|
2019-08-06 10:29:04 +02:00
|
|
|
var Int = jet.Int
|
2019-08-17 10:43:16 +02:00
|
|
|
|
2021-02-22 13:58:28 -05:00
|
|
|
// Int8 is constructor for 8 bit signed integer expressions literals.
|
|
|
|
|
var Int8 = jet.Int8
|
|
|
|
|
|
|
|
|
|
// Int16 is constructor for 16 bit signed integer expressions literals.
|
|
|
|
|
var Int16 = jet.Int16
|
|
|
|
|
|
|
|
|
|
// Int32 is constructor for 32 bit signed integer expressions literals.
|
|
|
|
|
var Int32 = jet.Int32
|
|
|
|
|
|
|
|
|
|
// Int64 is constructor for 64 bit signed integer expressions literals.
|
|
|
|
|
var Int64 = jet.Int
|
|
|
|
|
|
|
|
|
|
// Uint8 is constructor for 8 bit unsigned integer expressions literals.
|
|
|
|
|
var Uint8 = jet.Uint8
|
|
|
|
|
|
|
|
|
|
// Uint16 is constructor for 16 bit unsigned integer expressions literals.
|
|
|
|
|
var Uint16 = jet.Uint16
|
|
|
|
|
|
|
|
|
|
// Uint32 is constructor for 32 bit unsigned integer expressions literals.
|
|
|
|
|
var Uint32 = jet.Uint32
|
|
|
|
|
|
|
|
|
|
// Uint64 is constructor for 64 bit unsigned integer expressions literals.
|
|
|
|
|
var Uint64 = jet.Uint64
|
|
|
|
|
|
2021-05-09 16:25:54 +02:00
|
|
|
// Float creates new float literal expression from float64 value
|
2019-08-06 10:29:04 +02:00
|
|
|
var Float = jet.Float
|
2019-08-17 10:43:16 +02:00
|
|
|
|
2021-05-09 16:25:54 +02:00
|
|
|
// Decimal creates new float literal expression from string value
|
|
|
|
|
var Decimal = jet.Decimal
|
|
|
|
|
|
2019-08-17 10:43:16 +02:00
|
|
|
// String creates new string literal expression
|
2019-08-06 10:29:04 +02:00
|
|
|
var String = jet.String
|
|
|
|
|
|
2021-05-11 13:20:07 +02:00
|
|
|
// 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
|
|
|
|
|
|
2024-02-20 23:56:11 +05:30
|
|
|
// UUIDToBin takes ay object with a String method and calls StringUUIDToBin.
|
|
|
|
|
func UUIDToBin(str fmt.Stringer) StringExpression {
|
|
|
|
|
return StringUUIDToBin(str.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StringUUIDToBin is a helper function that calls "uuid_to_bin" function on the passed value.
|
|
|
|
|
func StringUUIDToBin(str string) StringExpression {
|
|
|
|
|
fn := Func("uuid_to_bin", String(str))
|
|
|
|
|
return StringExp(fn)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 10:43:16 +02:00
|
|
|
// Date creates new date literal
|
2022-05-16 11:51:47 +02:00
|
|
|
func Date(year int, month time.Month, day int) DateExpression {
|
2019-08-06 12:56:03 +02:00
|
|
|
return CAST(jet.Date(year, month, day)).AS_DATE()
|
|
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// DateT creates new date literal from time.Time
|
2022-05-16 11:51:47 +02:00
|
|
|
func DateT(t time.Time) DateExpression {
|
2019-08-06 11:41:45 +02:00
|
|
|
return CAST(jet.DateT(t)).AS_DATE()
|
|
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// Time creates new time literal
|
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-06 12:56:03 +02:00
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// TimeT creates new time literal from time.Time
|
2022-05-16 11:51:47 +02:00
|
|
|
func TimeT(t time.Time) TimeExpression {
|
2019-08-06 11:41:45 +02:00
|
|
|
return CAST(jet.TimeT(t)).AS_TIME()
|
|
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// DateTime creates new datetime literal
|
2022-05-16 11:51:47 +02:00
|
|
|
func DateTime(year int, month time.Month, day, hour, minute, second int, nanoseconds ...time.Duration) DateTimeExpression {
|
2019-08-13 10:16:26 +02:00
|
|
|
return CAST(jet.Timestamp(year, month, day, hour, minute, second, nanoseconds...)).AS_DATETIME()
|
2019-08-06 12:56:03 +02:00
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// DateTimeT creates new datetime literal from time.Time
|
2022-05-16 11:51:47 +02:00
|
|
|
func DateTimeT(t time.Time) DateTimeExpression {
|
2019-08-06 11:41:45 +02:00
|
|
|
return CAST(jet.TimestampT(t)).AS_DATETIME()
|
|
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// Timestamp creates new timestamp literal
|
2022-05-16 11:51:47 +02:00
|
|
|
func Timestamp(year int, month time.Month, day, hour, minute, second int, nanoseconds ...time.Duration) TimestampExpression {
|
2019-08-13 10:16:26 +02:00
|
|
|
return TIMESTAMP(StringExp(jet.Timestamp(year, month, day, hour, minute, second, nanoseconds...)))
|
2019-08-06 12:56:03 +02:00
|
|
|
}
|
2019-08-17 10:43:16 +02:00
|
|
|
|
|
|
|
|
// TimestampT creates new timestamp literal from time.Time
|
2022-05-16 11:51:47 +02:00
|
|
|
func TimestampT(t time.Time) TimestampExpression {
|
2019-08-06 13:58:17 +02:00
|
|
|
return TIMESTAMP(StringExp(jet.TimestampT(t)))
|
2019-08-06 11:41:45 +02:00
|
|
|
}
|