You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the value of a composition is static which greatly limits query re-usability. The first attempts at increasing this re-usability were the :count() and :union() style commands but they were fairly limited and greatly increase code complexity (it generates SQL which requires knowing which dialect of SQL a driver wants.
After a fair amount of using these compositions I have found it would be much easier (as well as more flexible) to write a query with a subquery that could easily be swapped out. For example writing a generic count query that works similar to the :count() macro as follows: SELECT COUNT(base.id) AS base_count FROM (:reference(ref_name)) base (referred to below as count_base.cql).
This query would compose whatever query ref_name is set to and count whatever column was specified as id.
This base.cql template could be used as follows: SELECT base_count FROM :compose(count_base.cql SETTING ref_name TO :compose(active_users.cql)
Assuming simple.cql was SELECT id, name FROM users WHERE active = 1 this would result in: SELECT COUNT(base.id) FROM (SELECT id, name FROM users WHERE active = 1) base allowing for a count query that is reusable for any other query with an id column and without having to alter the active_users.cql query in order to count these users.
If a query has a reference that is not provided by the calling macro using SETTING composition should fail.
If the SETTING keyword is used while composing a query without any references composition should also fail.
The text was updated successfully, but these errors were encountered:
when you say 'value of a composition is static', do you mean that the results are fixed at parsing, or do you mean it has a 'static lifetime? Or the fact that the composer produces the actual SQL for the backend rather than having some sort of re-usable type that can be converted to SQL in a jit manner at the end.
Is one of the goals to rework :count and :union internally to use the :setting keyword?
anyways, now that I'm looking at the code again, going to see if I remember and finally understand ComposerTrait, and most of the crate types, SqlComposition, SqlCompositionAlias, ParsedItem etc.
Currently the value of a composition is static which greatly limits query re-usability. The first attempts at increasing this re-usability were the
:count()
and:union()
style commands but they were fairly limited and greatly increase code complexity (it generates SQL which requires knowing which dialect of SQL a driver wants.After a fair amount of using these compositions I have found it would be much easier (as well as more flexible) to write a query with a subquery that could easily be swapped out. For example writing a generic count query that works similar to the
:count()
macro as follows:SELECT COUNT(base.id) AS base_count FROM (:reference(ref_name)) base
(referred to below as count_base.cql).This query would compose whatever query ref_name is set to and count whatever column was specified as id.
This base.cql template could be used as follows:
SELECT base_count FROM :compose(count_base.cql SETTING ref_name TO :compose(active_users.cql)
Assuming simple.cql was
SELECT id, name FROM users WHERE active = 1
this would result in:SELECT COUNT(base.id) FROM (SELECT id, name FROM users WHERE active = 1) base
allowing for a count query that is reusable for any other query with an id column and without having to alter theactive_users.cql
query in order to count these users.If a query has a reference that is not provided by the calling macro using SETTING composition should fail.
If the SETTING keyword is used while composing a query without any references composition should also fail.
The text was updated successfully, but these errors were encountered: