2019-03-30 10:17:32 +01:00
|
|
|
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-05-05 12:37:23 +02:00
|
|
|
|
2019-06-08 16:34:15 +02:00
|
|
|
Alias() string
|
2019-06-18 14:35:32 +02:00
|
|
|
|
|
|
|
|
AllColumns() ProjectionList
|
2019-05-05 12:37:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type expressionTableImpl struct {
|
2019-06-05 17:15:20 +02:00
|
|
|
readableTableInterfaceImpl
|
|
|
|
|
expression Expression
|
|
|
|
|
alias string
|
2019-06-18 14:35:32 +02:00
|
|
|
|
|
|
|
|
projections []projection
|
2019-06-05 17:15:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-18 14:35:32 +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
|
|
|
|
|
|
2019-06-18 14:35:32 +02:00
|
|
|
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-03-30 10:17:32 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2019-06-18 14:35:32 +02:00
|
|
|
func (e *expressionTableImpl) columns() []Column {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *expressionTableImpl) AllColumns() ProjectionList {
|
|
|
|
|
return e.projections
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 14:37:51 +02:00
|
|
|
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)
|
2019-03-30 10:17:32 +01:00
|
|
|
|
|
|
|
|
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)
|
2019-03-30 10:17:32 +01:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|