dev0
dev0
DTDrizzle Team
Created by dev0 on 5/17/2024 in #help
Effectively mixing QueryBuilder and sql`` using CTEs
Also tried the second approach. Haven't tried executing the query yet, but the resulting query string looks good. It's a little tricky to find the right spot to insert the addtional chunk, but outside of that it's pretty straight forward, too. I think what would be really useful was some form of escape hatch on all query builders that would allow for inserting arbitrary SQL chunks into the generated QueryBuilder chunk list. That's a powerful feature and a potential foot gun obviously, but it would make these kinds of use-cases so much easier to deal with.
5 replies
DTDrizzle Team
Created by dev0 on 5/17/2024 in #help
Effectively mixing QueryBuilder and sql`` using CTEs
I tried the first approach and it appears to be working great. I'll try some more approaches just to see what the cleanest way is.
5 replies
DTDrizzle Team
Created by dev0 on 5/17/2024 in #help
Effectively mixing QueryBuilder and sql`` using CTEs
I think I'm onto two possible approaches: 1) It appears I can create a "partial" query up to "set" and obtain the query string using toSQL. I assume I might be able to get the SQL, too using getSQL and then append the remaining parts of the query from from ${myCte} onwards. 2) I am also able to get the SQL from the complete query using getSQL. I could look into somehow inserting the sqlfrom ${myCte} into that before execution. Any additional recommendations or advice greatly appreciated. I enjoy working with Drizzle when I can stay fully within it's APIs. But sadly some very basic API surfaces are dearly missing, especially on the write side of things. I like that it has escape hatches, but they often feel too much "all or nothing". Would be great if some of those escape hatches where a little more "topical".
5 replies