Wouldn't it be nice if you could write your queries like this?
#| SELECT DISTINCT date_format(`last-updated`, '%i') minute
#| FROM instances
#| ORDER BY 1
method getReportingMinutes (Str $instance-id) is query { }
Or this...
#| -- getTicketReportData
#| SELECT
#| t.id `number`,
#| t.post_date `date`,
#| t.post_title `title`,
#| ts.meta_value `ticket-status`,
#| a.user_login `agent`,
#| d.name `department`,
#| STR_TO_DATE(cd.meta_value, '%Y-%m-%d %H:%i:%s') `closed-on`
#| FROM wp_posts t
#| INNER JOIN wp_postmeta aa ON aa.post_id = t.id
#| INNER JOIN wp_users a ON a.id = aa.meta_value
#| LEFT JOIN wp_term_relationships da ON da.object_id = t.id
#| INNER JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = da.term_taxonomy_id
#| LEFT JOIN wp_terms d ON d.term_id = da.term_taxonomy_id
#| INNER JOIN wp_postmeta ts ON ts.post_id = t.id
#| LEFT JOIN wp_postmeta cd ON cd.post_id = t.id
#| WHERE
#| t.post_type = 'ticket'
#| AND
#| aa.meta_key = '_wpas_assignee'
#| AND
#| tt.taxonomy = 'department'
#| AND
#| ts.meta_key = '_wpas_status'
#| AND
#| cd.meta_key = '_ticket_closed_on'
method getTicketReportData ($from, $to, :$extra-logic) is query<hash> { }
Also, note that parameters are allowed, but they must match up with the parameter marker ?
:
#| SELECT id FROM lightsail_instances WHERE data->"$.name" = ?
method getLightsailInstanceByName ($n)
is query<hash>
{ }
I am currently developing a system that does just that, and the two queries above are working examples!
Might this make more sense?
This has the extra advantage for allowing different types of queries, ala: