Default aliasing simplified.

This commit is contained in:
go-jet 2019-06-09 11:06:08 +02:00
parent e772768180
commit ffba8718ca
11 changed files with 46 additions and 70 deletions

View file

@ -10,11 +10,7 @@ type column interface {
Name() string
TableName() string
// Internal function for tracking tableName that a column belongs to
// for the purpose of serialization
setTableName(table string)
defaultAlias() string
defaultAliasProjection() projection
}
type Column interface {
@ -61,10 +57,6 @@ func (c *columnImpl) defaultAlias() string {
return c.name
}
func (c *columnImpl) defaultAliasProjection() projection {
return c.AS(c.defaultAlias())
}
func (c *columnImpl) serializeAsOrderBy(statement statementType, out *queryData) error {
if statement == set_statement {
// set Statement (UNION, EXCEPT ...) can reference only select projections in order by clause
@ -84,6 +76,18 @@ func (c *columnImpl) serializeAsOrderBy(statement statementType, out *queryData)
return c.serialize(statement, out)
}
func (c columnImpl) serializeForProjection(statement statementType, out *queryData) error {
err := c.serialize(statement, out)
if err != nil {
return err
}
out.writeString(`AS "` + c.defaultAlias() + `"`)
return nil
}
func (c columnImpl) serialize(statement statementType, out *queryData, options ...serializeOption) error {
columnRef := ""