Conditional segments of queries
See original GitHub issueDescription
Minimal condition query segments would be useful, and can be based exclusively around named parameters or flag variables.
For example, two conditionals in this statement, one could just use the empty list without conditional although it makes a silly query, but the 2nd case requires the conditional.
selectPosts:
SELECT *
FROM posts
WHERE authorId NOT IN :muteUserList
AND category IN :categoryList
;
This is not intended as final syntax, but uses a tag plus Kotlin conditional that maybe helps code compilation to inject that code directly into the calling logic or as a lambda. Nesting might also be needed.
Of course you could write multiple queries, but large queries that have complex bases would be painful to maintain 4 or 5 copies for small variations.
You could use CTE’s if you could nest queries and then further refine it, but that doesn’t work in all cases such as those requiring a join and a where clause item, that have big impact on the primary query.
nesting queries maybe is another helpful flavor of this conditional or compound query structuring:
selectSomePosts:
SELECT *
FROM {{selectPosts}}
WHERE authorId NOT IN :muteUserList
AND category IN :categoryList
;
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6
Top GitHub Comments
CASE is work around for some but not all issues (optional joins, subqueries, …)
This works https://github.com/cashapp/sqldelight/issues/626#issuecomment-1213319111