Alias serialize simplified.
This commit is contained in:
parent
fb5bf7dd40
commit
cd1d033ffb
3 changed files with 17 additions and 22 deletions
19
alias.go
19
alias.go
|
|
@ -3,8 +3,6 @@ package jet
|
||||||
type alias struct {
|
type alias struct {
|
||||||
expression Expression
|
expression Expression
|
||||||
alias string
|
alias string
|
||||||
|
|
||||||
subQuery ExpressionTable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAlias(expression Expression, aliasName string) projection {
|
func newAlias(expression Expression, aliasName string) projection {
|
||||||
|
|
@ -15,25 +13,22 @@ func newAlias(expression Expression, aliasName string) projection {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *alias) from(subQuery ExpressionTable) projection {
|
func (a *alias) from(subQuery ExpressionTable) projection {
|
||||||
newAlias := *a
|
column := newColumn(a.alias, "", nil)
|
||||||
newAlias.subQuery = subQuery
|
column.parent = &column
|
||||||
return &newAlias
|
column.subQuery = subQuery
|
||||||
|
|
||||||
|
return &column
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *alias) serializeForProjection(statement statementType, out *queryData) error {
|
func (a *alias) serializeForProjection(statement statementType, out *queryData) error {
|
||||||
if a.subQuery != nil {
|
|
||||||
out.writeIdentifier(a.subQuery.Alias())
|
|
||||||
out.writeByte('.')
|
|
||||||
out.writeQuotedString(a.alias)
|
|
||||||
} else {
|
|
||||||
err := a.expression.serialize(statement, out)
|
err := a.expression.serialize(statement, out)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
out.writeString(`AS "` + a.alias + `"`)
|
out.writeString("AS ")
|
||||||
|
out.writeQuotedString(a.alias)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ func (c columnImpl) serialize(statement statementType, out *queryData, options .
|
||||||
if c.subQuery != nil {
|
if c.subQuery != nil {
|
||||||
out.writeIdentifier(c.subQuery.Alias())
|
out.writeIdentifier(c.subQuery.Alias())
|
||||||
out.writeByte('.')
|
out.writeByte('.')
|
||||||
out.writeString(`"` + c.defaultAlias() + `"`)
|
out.writeQuotedString(c.defaultAlias())
|
||||||
} else {
|
} else {
|
||||||
if c.tableName != "" {
|
if c.tableName != "" {
|
||||||
out.writeIdentifier(c.tableName)
|
out.writeIdentifier(c.tableName)
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ Above statement will produce following result set:
|
||||||
| _3_| 589 | "York" | 502 | "1515 Korla Way" | 497 | "Sledge" |
|
| _3_| 589 | "York" | 502 | "1515 Korla Way" | 497 | "Sledge" |
|
||||||
|
|
||||||
Lets execute statement and scan result set to destination `dest`:
|
Lets execute statement and scan result set to destination `dest`:
|
||||||
```
|
```sql
|
||||||
var dest []struct {
|
var dest []struct {
|
||||||
model.City
|
model.City
|
||||||
|
|
||||||
|
|
@ -190,7 +190,7 @@ City of `London` has two customers, which is the product of object reuse in `ROW
|
||||||
|
|
||||||
### Custom model files
|
### Custom model files
|
||||||
|
|
||||||
**Programmes are not limited to just model files, any destination will work, as long as camel case of result set column
|
**Destinations are not limited to just model files, any destination will work, as long as camel case of result set column
|
||||||
is equal to `model type name`.`field name`.**
|
is equal to `model type name`.`field name`.**
|
||||||
|
|
||||||
#### Named types
|
#### Named types
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue