getandlist
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const deprecateQuery = `-- name: DeprecateQuery :exec
|
||||
INSERT INTO queryDeprecations (queryId) VALUES ($1) RETURNING id
|
||||
INSERT INTO queryDeprecations (queryId) VALUES ($1)
|
||||
`
|
||||
|
||||
func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error {
|
||||
@@ -98,3 +98,49 @@ func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (b
|
||||
err := row.Scan(&exists)
|
||||
return exists, err
|
||||
}
|
||||
|
||||
const listQueries = `-- 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
|
||||
GROUP BY q.id, c.config
|
||||
`
|
||||
|
||||
type ListQueriesRow struct {
|
||||
ID pgtype.UUID
|
||||
Type Querytype
|
||||
Activeversion int32
|
||||
Config []byte
|
||||
Requiredids []pgtype.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ListQueries(ctx context.Context) ([]ListQueriesRow, error) {
|
||||
rows, err := q.db.Query(ctx, listQueries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListQueriesRow
|
||||
for rows.Next() {
|
||||
var i ListQueriesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Type,
|
||||
&i.Activeversion,
|
||||
&i.Config,
|
||||
&i.Requiredids,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user