K
Kysely7mo ago
mike

Snippet compilation

Hi, is it somehow possible to get only part of the compiled code to use it as snippet in ORM? Or vice-versa is it possible to build only part of the code with type helpers and compile them without the parent query? For example I would like to get only the code for the header_index and header_order aliases:
SELECT
code,
name,
priority,
header,
CASE
WHEN header IS NULL THEN 0
ELSE MIN(priority) OVER (PARTITION BY header)
END AS header_index,
ROW_NUMBER() OVER (PARTITION BY header ORDER BY priority) AS header_order
FROM
Product
ORDER BY
header_index,
priority;
SELECT
code,
name,
priority,
header,
CASE
WHEN header IS NULL THEN 0
ELSE MIN(priority) OVER (PARTITION BY header)
END AS header_index,
ROW_NUMBER() OVER (PARTITION BY header ORDER BY priority) AS header_order
FROM
Product
ORDER BY
header_index,
priority;
Solution:
There are many ways to do this, but here are couple of them: https://kyse.link/Ion4f
Jump to solution
2 Replies
Solution
koskimas
koskimas7mo ago
There are many ways to do this, but here are couple of them: https://kyse.link/Ion4f
koskimas
koskimas7mo ago
to use it as snippet in ORM
Just to be clear, Kysely is not an ORM in any way or form Haha, it rhymed
Want results from more Discord servers?
Add your server