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 {
|
||||
expression Expression
|
||||
alias string
|
||||
|
||||
subQuery ExpressionTable
|
||||
}
|
||||
|
||||
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 {
|
||||
newAlias := *a
|
||||
newAlias.subQuery = subQuery
|
||||
return &newAlias
|
||||
column := newColumn(a.alias, "", nil)
|
||||
column.parent = &column
|
||||
column.subQuery = subQuery
|
||||
|
||||
return &column
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
out.writeString(`AS "` + a.alias + `"`)
|
||||
out.writeString("AS ")
|
||||
out.writeQuotedString(a.alias)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func (c columnImpl) serialize(statement statementType, out *queryData, options .
|
|||
if c.subQuery != nil {
|
||||
out.writeIdentifier(c.subQuery.Alias())
|
||||
out.writeByte('.')
|
||||
out.writeString(`"` + c.defaultAlias() + `"`)
|
||||
out.writeQuotedString(c.defaultAlias())
|
||||
} else {
|
||||
if 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" |
|
||||
|
||||
Lets execute statement and scan result set to destination `dest`:
|
||||
```
|
||||
```sql
|
||||
var dest []struct {
|
||||
model.City
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ City of `London` has two customers, which is the product of object reuse in `ROW
|
|||
|
||||
### 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`.**
|
||||
|
||||
#### Named types
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue