Merge pull request #361 from mathieuk/chore/export-serializer

feat: export CustomExpression and Token for dialects to use
This commit is contained in:
go-jet 2024-07-14 13:14:58 +02:00 committed by GitHub
commit df548e69b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 3 deletions

View file

@ -278,7 +278,7 @@ type customExpression struct {
parts []Serializer parts []Serializer
} }
func newCustomExpression(parts ...Serializer) Expression { func CustomExpression(parts ...Serializer) Expression {
ret := customExpression{ ret := customExpression{
parts: parts, parts: parts,
} }

View file

@ -548,7 +548,7 @@ func TO_TIMESTAMP(timestampzStr, format StringExpression) TimestampzExpression {
// EXTRACT extracts time component from time expression // EXTRACT extracts time component from time expression
func EXTRACT(field string, from Expression) Expression { func EXTRACT(field string, from Expression) Expression {
return newCustomExpression(Token("EXTRACT("), Token(field), Token("FROM"), from, Token(")")) return CustomExpression(Token("EXTRACT("), Token(field), Token("FROM"), from, Token(")"))
} }
// CURRENT_DATE returns current date // CURRENT_DATE returns current date

View file

@ -35,7 +35,7 @@ func GROUPING(expressions ...Expression) IntegerExpression {
// WITH_ROLLUP operator is used with the GROUP BY clause to generate all prefixes of a group of columns including the empty list. // WITH_ROLLUP operator is used with the GROUP BY clause to generate all prefixes of a group of columns including the empty list.
// It creates extra rows in the result set that represent the subtotal values for each combination of columns. // It creates extra rows in the result set that represent the subtotal values for each combination of columns.
func WITH_ROLLUP(expressions ...Expression) GroupByClause { func WITH_ROLLUP(expressions ...Expression) GroupByClause {
return newCustomExpression( return CustomExpression(
parametersSerializer(expressions), Token("WITH ROLLUP"), parametersSerializer(expressions), Token("WITH ROLLUP"),
) )
} }

View file

@ -70,6 +70,12 @@ var DateTimeExp = jet.TimestampExp
// Does not add sql cast to generated sql builder output. // Does not add sql cast to generated sql builder output.
var TimestampExp = jet.TimestampExp var TimestampExp = jet.TimestampExp
// CustomExpression is used to define custom expressions.
var CustomExpression = jet.CustomExpression
// Token is used to define custom token in a custom expression.
type Token = jet.Token
// RawArgs is type used to pass optional arguments to Raw method // RawArgs is type used to pass optional arguments to Raw method
type RawArgs = map[string]interface{} type RawArgs = map[string]interface{}

View file

@ -111,6 +111,12 @@ var (
TstzRangeExp = jet.TstzRangeExp TstzRangeExp = jet.TstzRangeExp
) )
// CustomExpression is used to define custom expressions.
var CustomExpression = jet.CustomExpression
// Token is used to define custom token in a custom expression.
type Token = jet.Token
// RawArgs is type used to pass optional arguments to Raw method // RawArgs is type used to pass optional arguments to Raw method
type RawArgs = map[string]interface{} type RawArgs = map[string]interface{}

View file

@ -73,6 +73,12 @@ var DateTimeExp = jet.TimestampExp
// Does not add sql cast to generated sql builder output. // Does not add sql cast to generated sql builder output.
var TimestampExp = jet.TimestampExp var TimestampExp = jet.TimestampExp
// CustomExpression is used to define custom expressions.
var CustomExpression = jet.CustomExpression
// Token is used to define custom token in a custom expression.
type Token = jet.Token
// RawArgs is type used to pass optional arguments to Raw method // RawArgs is type used to pass optional arguments to Raw method
type RawArgs = map[string]interface{} type RawArgs = map[string]interface{}