jet/sqlbuilder/expression_table.go

63 lines
1.2 KiB
Go
Raw Normal View History

package sqlbuilder
2019-05-13 12:33:11 +02:00
import "errors"
2019-06-08 16:34:15 +02:00
type ExpressionTable interface {
2019-06-04 12:10:23 +02:00
ReadableTable
2019-06-08 16:34:15 +02:00
Alias() string
AllColumns() ProjectionList
}
type expressionTableImpl struct {
2019-06-05 17:15:20 +02:00
readableTableInterfaceImpl
expression Expression
alias string
projections []projection
2019-06-05 17:15:20 +02:00
}
func newExpressionTable(expression Expression, alias string, projections []projection) ExpressionTable {
2019-06-05 17:15:20 +02:00
expTable := &expressionTableImpl{expression: expression, alias: alias}
expTable.readableTableInterfaceImpl.parent = expTable
for _, projection := range projections {
newProjection := projection.from(expTable)
expTable.projections = append(expTable.projections, newProjection)
}
2019-06-05 17:15:20 +02:00
return expTable
}
2019-06-08 16:34:15 +02:00
func (e *expressionTableImpl) Alias() string {
2019-05-13 12:33:11 +02:00
return e.alias
2019-04-07 09:58:12 +02:00
}
func (e *expressionTableImpl) columns() []Column {
return nil
}
func (e *expressionTableImpl) AllColumns() ProjectionList {
return e.projections
}
func (e *expressionTableImpl) serialize(statement statementType, out *queryData, options ...serializeOption) error {
2019-05-13 12:33:11 +02:00
if e == nil {
return errors.New("Expression table is nil. ")
}
2019-06-08 16:34:15 +02:00
2019-06-05 17:15:20 +02:00
err := e.expression.serialize(statement, out)
if err != nil {
return err
}
2019-05-12 18:15:23 +02:00
out.writeString("AS")
2019-06-17 12:05:52 +02:00
out.writeIdentifier(e.alias)
return nil
}