Files
query-orchestration/database/queries/query.sql
T

36 lines
1.4 KiB
SQL
Raw Normal View History

2024-12-23 12:26:05 +00:00
-- name: GetQueryConfig :one
2025-01-03 10:35:42 +00:00
SELECT id, config FROM queryConfigs where queryId = $1 and addedVersion >= $2 and COALESCE(removedVersion, $2 - 1) < $2;
2025-01-03 13:41:07 +00:00
-- name: GetQueryType :one
SELECT type FROM queries where id = $1;
-- name: DeprecateQuery :exec
2025-01-03 14:08:04 +00:00
INSERT INTO queryDeprecations (queryId) VALUES ($1);
2025-01-03 13:41:07 +00:00
-- name: IsQueryDeprecated :one
SELECT EXISTS (
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is not null
);
2025-01-03 10:35:42 +00:00
-- name: GetQuery :one
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
FROM queries AS q
JOIN queryConfigs AS c ON q.id = c.queryId
JOIN requiredQueries AS r ON q.id = r.queryId
WHERE q.id = $1
and c.addedVersion >= q.activeVersion
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
and r.addedVersion >= q.activeVersion
and COALESCE(r.removedVersion, q.activeVersion - 1) < q.activeVersion
2025-01-03 14:08:04 +00:00
GROUP BY q.id, c.config;
-- name: ListQueries :many
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
FROM queries AS q
JOIN queryConfigs AS c ON q.id = c.queryId
JOIN requiredQueries AS r ON q.id = r.queryId
WHERE c.addedVersion >= q.activeVersion
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
and r.addedVersion >= q.activeVersion
and COALESCE(r.removedVersion, q.activeVersion - 1) < q.activeVersion
2025-01-03 10:35:42 +00:00
GROUP BY q.id, c.config;