diff --git a/alias.go b/alias.go index 13a1584..8f156fd 100644 --- a/alias.go +++ b/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) + err := a.expression.serialize(statement, out) - if err != nil { - return err - } + if err != nil { + return err } - out.writeString(`AS "` + a.alias + `"`) + out.writeString("AS ") + out.writeQuotedString(a.alias) return nil } diff --git a/column.go b/column.go index 2a54361..e3af1a8 100644 --- a/column.go +++ b/column.go @@ -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) diff --git a/wiki/Scan-to-arbitrary-destination.md b/wiki/Scan-to-arbitrary-destination.md index 038c106..f4e0d7d 100644 --- a/wiki/Scan-to-arbitrary-destination.md +++ b/wiki/Scan-to-arbitrary-destination.md @@ -51,13 +51,13 @@ Every column is aliased by default. Format is "`table_name`.`column_name`" Above statement will produce following result set: |_row_| city.city_id | city.city | address.address_id | address.address | customer.customer_id | customer.last_name | -|---| ------------ | ------------- | ------------------- | -------------------- | -------------------- | ------------------ | -| _1_| 312 | "London" | 256 | "1497 Yuzhou Drive" | 252 | "Hoffman"| -| _2_| 312 | "London" | 517 | "548 Uruapan Street"| 512 | "Vines" | -| _3_| 589 | "York" | 502 | "1515 Korla Way" | 497 | "Sledge" | +|--- | ------------ | ------------- | ------------------- | -------------------- | -------------------- | ------------------ | +| _1_| 312 | "London" | 256 | "1497 Yuzhou Drive" | 252 | "Hoffman"| +| _2_| 312 | "London" | 517 | "548 Uruapan Street" | 512 | "Vines" | +| _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