WITH RECURSIVE support… or suggestions for how to approach?
Hi. I'm absolutely loving Drizzle after a little while in both Prisma and TypeORM and 15 years of Rails + ActiveRecord.
I have the following query that uses WITH RECURSIVE. I'd love to use Drizzle's query builder but I cant see how I might tackle that. Am I right in thinking that this is going to need to be supported in the
select
helper https://orm.drizzle.team/docs/select#with-clause ?
```
WITH RECURSIVE layer AS (
SELECT
id,
name,
parent_id,
0 AS level
FROM
risks
WHERE
parent_id IS NULL
UNION ALL
SELECT
child.id,
child.name,
child.parent_id,
level + 1 AS level
FROM
risks child
JOIN layer l ON l.id = child.parent_id
)
SELECT
l.*,
parent.id AS parent_id
FROM
layer l
LEFT JOIN risks parent ON l.parent_id = parent.id
ORDER BY
level;SQL Select - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
4 Replies
This is coming very soon. See here: https://github.com/drizzle-team/drizzle-orm/pull/1405
GitHub
Feat: select without from and with recursive by Angelelz · Pull Req...
This will close #372 and will close #209. Also related to #1215?
This PR depends on #1218.
Upon merging, It will be possible to write a select statement without the .from() method. That will make p...
Oh, amazing – great stuff @Angelelz – and what fortuitous timing (for me), especially with the
union
stuff having just dropped.@Angelelz do you think this will be able to land soon? This is something that we use a lot in our codebase. Thanks 😊
I believe I saw it somewhere that after the drizzle kit upgrades, this was next