Block syntax in row query select removed from query API
In 9.0, the Gosu language no longer supports
block syntax as an argument to the query builder select method. Gosu retains equivalent
functionality for selecting columns from the application database for
a row query. The select
method now accepts an array of objects that implement the IQuerySelectColumn interface.
Configuration upgrade tools for Version 9.0 convert legacy arguments
for the query builder select
method to equivalent query builder code.
For example, the query builder select method in the following
example Gosu code from earlier versions of BillingCenter returns rows
that contain ChargeAmount
and ProducerName columns.
uses gw.api.database.Query
// Query for invoice items.
var queryInvoiceItems = Query.make(InvoiceItem)
var resultInvoiceItems = queryInvoiceItems.select(
\ invoiceItem -> ({
"ChargeAmount" -> invoiceItem.Charge.Amount,
"ProducerName" -> invoiceItem.PolicyPeriod.PrimaryPolicyCommission.ProducerCode.Producer.Name
})
)
// With a row query, the result contains only the data you need.
for (row in resultInvoiceItems) {
var chargeAmount = row.get("ChargeAmount")
var producerName = row.get("ProducerName")
print(chargeAmount + " charged to producer " + producerName)
}
After upgrade, the preceding block is converted to
the following query builder code, which also returns rows that contain
ChargeAmount and ProducerName columns.
uses gw.api.database.Query
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths
// Query for invoice items.
var queryInvoiceItems = Query.make(InvoiceItem)
var resultInvoiceItems = queryInvoiceItems.select({
QuerySelectColumns.pathWithAlias("Charge", Paths.make(InvoiceItem#Charge)),
QuerySelectColumns.pathWithAlias("ProducerName",
Paths.make(InvoiceItem#PolicyPeriod,
PolicyPeriod#PrimaryPolicyCommission,
PolicyCommission#ProducerCode,
ProducerCode#Producer,
Producer#Name))
})
// With a row query, the result contains only the data you need.
for (row in resultInvoiceItems) {
var charge = row.getColumn("Charge")
var producerName = row.getColumn("ProducerName")
print(charge + " charged to producer " + producerName)
}
See also
