From 92d02fef78229ae586f7ec2d37699058d9a4c47f Mon Sep 17 00:00:00 2001 From: go-jet Date: Sun, 9 May 2021 16:25:54 +0200 Subject: [PATCH] Add DECIMAL constructor for Float literal. DECIMAL constructor is used to pass a decimal number to the SQL query without precision loss. --- internal/jet/literal_expression.go | 12 +++++++++++- mysql/literal.go | 5 ++++- postgres/literal.go | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/jet/literal_expression.go b/internal/jet/literal_expression.go index aed31b0..b86cb8e 100644 --- a/internal/jet/literal_expression.go +++ b/internal/jet/literal_expression.go @@ -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 diff --git a/mysql/literal.go b/mysql/literal.go index 7523d55..4a6544c 100644 --- a/mysql/literal.go +++ b/mysql/literal.go @@ -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 diff --git a/postgres/literal.go b/postgres/literal.go index a0b0224..ebfd85c 100644 --- a/postgres/literal.go +++ b/postgres/literal.go @@ -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