Functions go doc.

This commit is contained in:
go-jet 2019-08-14 10:11:43 +02:00
parent 13c671fa3f
commit 4ab9d73a8b
7 changed files with 141 additions and 59 deletions

View file

@ -11,7 +11,7 @@ type Clause interface {
type ClauseWithProjections interface {
Clause
projections() []Projection
projections() ProjectionList
}
type ClauseSelect struct {
@ -19,7 +19,7 @@ type ClauseSelect struct {
Projections []Projection
}
func (s *ClauseSelect) projections() []Projection {
func (s *ClauseSelect) projections() ProjectionList {
return s.Projections
}
@ -172,7 +172,7 @@ type ClauseSetStmtOperator struct {
Offset ClauseOffset
}
func (s *ClauseSetStmtOperator) projections() []Projection {
func (s *ClauseSetStmtOperator) projections() ProjectionList {
if len(s.Selects) > 0 {
return s.Selects[0].projections()
}

View file

@ -17,10 +17,12 @@ func ABSi(integerExpression IntegerExpression) IntegerExpression {
return newIntegerFunc("ABS", integerExpression)
}
// POW calculates power of base with exponent
func POW(base, exponent NumericExpression) FloatExpression {
return NewFloatFunc("POW", base, exponent)
}
// POWER calculates power of base with exponent
func POWER(base, exponent NumericExpression) FloatExpression {
return NewFloatFunc("POWER", base, exponent)
}
@ -202,12 +204,14 @@ func CHR(integerExpression IntegerExpression) StringExpression {
return newStringFunc("CHR", integerExpression)
}
// CONCAT adds two or more expressions together
func CONCAT(expressions ...Expression) StringExpression {
return newStringFunc("CONCAT", expressions...)
}
func CONCAT_WS(expressions ...Expression) StringExpression {
return newStringFunc("CONCAT_WS", expressions...)
// CONCAT_WS adds two or more expressions together with a separator.
func CONCAT_WS(separator Expression, expressions ...Expression) StringExpression {
return newStringFunc("CONCAT_WS", append([]Expression{separator}, expressions...)...)
}
// CONVERT converts string to dest_encoding. The original encoding is
@ -240,6 +244,7 @@ func DECODE(data StringExpression, format StringExpression) StringExpression {
return newStringFunc("DECODE", data, format)
}
// FORMAT formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places, then it returns the result as a string.
func FORMAT(formatStr StringExpression, formatArgs ...Expression) StringExpression {
args := []Expression{formatStr}
args = append(args, formatArgs...)
@ -341,6 +346,7 @@ func TO_HEX(number IntegerExpression) StringExpression {
return newStringFunc("TO_HEX", number)
}
// REGEXP_LIKE Returns 1 if the string expr matches the regular expression specified by the pattern pat, 0 otherwise.
func REGEXP_LIKE(stringExp StringExpression, pattern StringExpression, matchType ...string) BoolExpression {
if len(matchType) > 0 {
return newBoolFunc("REGEXP_LIKE", stringExp, pattern, String(matchType[0], true))

View file

@ -10,17 +10,14 @@ type SelectTableImpl struct {
selectStmt StatementWithProjections
alias string
projections []Projection
projections ProjectionList
}
func NewSelectTable(selectStmt StatementWithProjections, alias string) SelectTableImpl {
selectTable := SelectTableImpl{selectStmt: selectStmt, alias: alias}
for _, projection := range selectStmt.projections() {
newProjection := projection.fromImpl(&selectTable)
selectTable.projections = append(selectTable.projections, newProjection)
}
projectionList := selectStmt.projections().fromImpl(&selectTable)
selectTable.projections = projectionList.(ProjectionList)
return selectTable
}

View file

@ -39,7 +39,7 @@ type StatementWithProjections interface {
}
type HasProjections interface {
projections() []Projection
projections() ProjectionList
}
type SerializerStatementInterfaceImpl struct {
@ -116,7 +116,7 @@ type StatementImpl struct {
Clauses []Clause
}
func (s *StatementImpl) projections() []Projection {
func (s *StatementImpl) projections() ProjectionList {
for _, clause := range s.Clauses {
if selectClause, ok := clause.(ClauseWithProjections); ok {
return selectClause.projections()