Add DECIMAL constructor for Float literal.

DECIMAL constructor is used to pass a decimal number to the SQL query without precision loss.
This commit is contained in:
go-jet 2021-05-09 16:25:54 +02:00
parent 08cc316101
commit 92d02fef78
3 changed files with 18 additions and 2 deletions

View file

@ -140,7 +140,7 @@ type floatLiteral struct {
literalExpressionImpl
}
// Float creates new float literal
// Float creates new float literal from float64 value
func Float(value float64) FloatExpression {
floatLiteral := floatLiteral{}
floatLiteral.literalExpressionImpl = *literal(value)
@ -150,6 +150,16 @@ func Float(value float64) FloatExpression {
return &floatLiteral
}
// Decimal creates new float literal from string value
func Decimal(value string) FloatExpression {
floatLiteral := floatLiteral{}
floatLiteral.literalExpressionImpl = *literal(value)
floatLiteral.floatInterfaceImpl.parent = &floatLiteral
return &floatLiteral
}
//---------------------------------------------------//
type stringLiteral struct {
stringInterfaceImpl

View file

@ -42,9 +42,12 @@ var Uint32 = jet.Uint32
// Uint64 is constructor for 64 bit unsigned integer expressions literals.
var Uint64 = jet.Uint64
// Float creates new float literal expression
// Float creates new float literal expression from float64 value
var Float = jet.Float
// Decimal creates new float literal expression from string value
var Decimal = jet.Decimal
// String creates new string literal expression
var String = jet.String

View file

@ -38,6 +38,9 @@ var Uint64 = jet.Uint64
// Float creates new float literal expression
var Float = jet.Float
// Decimal creates new float literal expression
var Decimal = jet.Decimal
// String creates new string literal expression
var String = jet.String