Created
July 20, 2024 14:40
-
-
Save samccone/88c74400966e88a5219f114a1bdc87e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE transitive_dependencies AS ( | |
SELECT package_id AS dependency_id, package_id AS root_id | |
FROM dependencies | |
WHERE kind = 'runtime' | |
UNION ALL | |
SELECT d.package_id, td.root_id | |
FROM dependencies d | |
JOIN transitive_dependencies td ON td.dependency_id = d.package_id AND td.dependency_id <> td.root_id -- Avoid self-joins | |
WHERE d.kind = 'runtime' | |
), | |
dependency_counts AS ( | |
SELECT root_id, COUNT(*) AS dependency_count | |
FROM transitive_dependencies | |
GROUP BY root_id | |
) | |
SELECT p.name, dc.dependency_count | |
FROM dependency_counts dc | |
JOIN packages p ON p.id = dc.root_id | |
ORDER BY dc.dependency_count DESC | |
LIMIT 25; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment