Simplify construction of new expressions.
Fixes: IS_NOT_NULL() does not always add enough parentheses to the compiled SQL #500
This commit is contained in:
parent
95224a793f
commit
4995a90483
26 changed files with 466 additions and 543 deletions
|
|
@ -3,8 +3,9 @@ package postgres
|
|||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
)
|
||||
|
||||
// Dialect is implementation of postgres dialect for SQL Builder serialisation.
|
||||
|
|
@ -42,7 +43,7 @@ func newDialect() jet.Dialect {
|
|||
case TimezExpression:
|
||||
return CustomExpression(Token("'0000-01-01T' || to_char('2000-10-10'::date + "), e, Token(`, 'HH24:MI:SS.USTZH:TZM')`))
|
||||
case TimestampExpression:
|
||||
return CustomExpression(Token("to_char("), e, Token(`, 'YYYY-MM-DD"T"HH24:MI:SS.USZ')`))
|
||||
return jet.AtomicCustomExpression(Token("to_char("), e, Token(`, 'YYYY-MM-DD"T"HH24:MI:SS.USZ')`))
|
||||
case DateExpression:
|
||||
return CustomExpression(Token("to_char("), e, Token(`::timestamp, 'YYYY-MM-DD') || 'T00:00:00Z'`))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -552,10 +552,10 @@ func DATE_TRUNC(field unit, source Expression, timezone ...string) TimestampExpr
|
|||
// GENERATE_SERIES generates a series of values from start to stop, with a step size of step.
|
||||
func GENERATE_SERIES(start Expression, stop Expression, step ...Expression) Expression {
|
||||
if len(step) > 0 {
|
||||
return jet.NewFunc("GENERATE_SERIES", []Expression{start, stop, step[0]}, nil)
|
||||
return Func("GENERATE_SERIES", start, stop, step[0])
|
||||
}
|
||||
|
||||
return jet.NewFunc("GENERATE_SERIES", []Expression{start, stop}, nil)
|
||||
return Func("GENERATE_SERIES", start, stop)
|
||||
}
|
||||
|
||||
// --------------- Conditional Expressions Functions -------------//
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package postgres
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/utils/datetime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
"github.com/go-jet/jet/v2/internal/utils/datetime"
|
||||
)
|
||||
|
||||
type quantityAndUnit = float64
|
||||
|
|
@ -44,7 +46,7 @@ func INTERVAL(quantityAndUnit ...quantityAndUnit) IntervalExpression {
|
|||
fields = append(fields, quantity+" "+unitString)
|
||||
}
|
||||
|
||||
return IntervalExp(CustomExpression(Token(fmt.Sprintf("INTERVAL '%s'", strings.Join(fields, " ")))))
|
||||
return IntervalExp(jet.AtomicCustomExpression(Token(fmt.Sprintf("INTERVAL '%s'", strings.Join(fields, " ")))))
|
||||
}
|
||||
|
||||
// INTERVALd creates interval expression from time.Duration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue