Skip to content

Instantly share code, notes, and snippets.

@samccone
Created July 20, 2024 14:40
Show Gist options
  • Save samccone/88c74400966e88a5219f114a1bdc87e2 to your computer and use it in GitHub Desktop.
Save samccone/88c74400966e88a5219f114a1bdc87e2 to your computer and use it in GitHub Desktop.
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