2024-12-23 12:26:05 +00:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
|
// versions:
|
|
|
|
|
// sqlc v1.27.0
|
|
|
|
|
// source: query.sql
|
|
|
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-06 12:26:28 +00:00
|
|
|
const createQuery = `-- name: CreateQuery :one
|
|
|
|
|
INSERT INTO queries (type) VALUES ($1) RETURNING id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func (q *Queries) CreateQuery(ctx context.Context, type_ Querytype) (pgtype.UUID, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, createQuery, type_)
|
|
|
|
|
var id pgtype.UUID
|
|
|
|
|
err := row.Scan(&id)
|
|
|
|
|
return id, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createQueryConfig = `-- name: CreateQueryConfig :exec
|
|
|
|
|
INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type CreateQueryConfigParams struct {
|
|
|
|
|
Queryid pgtype.UUID
|
|
|
|
|
Config []byte
|
|
|
|
|
Addedversion int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) CreateQueryConfig(ctx context.Context, arg CreateQueryConfigParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, createQueryConfig, arg.Queryid, arg.Config, arg.Addedversion)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createRequiredQuery = `-- name: CreateRequiredQuery :exec
|
|
|
|
|
INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type CreateRequiredQueryParams struct {
|
|
|
|
|
Queryid pgtype.UUID
|
|
|
|
|
Requiredqueryid pgtype.UUID
|
|
|
|
|
Addedversion int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) CreateRequiredQuery(ctx context.Context, arg CreateRequiredQueryParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, createRequiredQuery, arg.Queryid, arg.Requiredqueryid, arg.Addedversion)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-03 13:41:07 +00:00
|
|
|
const deprecateQuery = `-- 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
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, deprecateQuery, queryid)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-03 10:35:42 +00:00
|
|
|
const getQuery = `-- name: GetQuery :one
|
2025-01-07 16:12:18 +00:00
|
|
|
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(DISTINCT r.requiredQueryId) as requiredIds
|
2025-01-03 10:35:42 +00:00
|
|
|
FROM queries AS q
|
2025-01-07 16:12:18 +00:00
|
|
|
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
|
|
|
|
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
2025-01-03 10:35:42 +00:00
|
|
|
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
|
|
|
|
|
GROUP BY q.id, c.config
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type GetQueryRow struct {
|
|
|
|
|
ID pgtype.UUID
|
|
|
|
|
Type Querytype
|
|
|
|
|
Activeversion int32
|
2025-01-03 14:21:14 +00:00
|
|
|
Latestversion int32
|
2025-01-03 10:35:42 +00:00
|
|
|
Config []byte
|
|
|
|
|
Requiredids []pgtype.UUID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) GetQuery(ctx context.Context, id pgtype.UUID) (GetQueryRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, getQuery, id)
|
|
|
|
|
var i GetQueryRow
|
|
|
|
|
err := row.Scan(
|
|
|
|
|
&i.ID,
|
|
|
|
|
&i.Type,
|
|
|
|
|
&i.Activeversion,
|
2025-01-03 14:21:14 +00:00
|
|
|
&i.Latestversion,
|
2025-01-03 10:35:42 +00:00
|
|
|
&i.Config,
|
|
|
|
|
&i.Requiredids,
|
|
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 12:26:05 +00:00
|
|
|
const getQueryConfig = `-- name: GetQueryConfig :one
|
|
|
|
|
SELECT id, config FROM queryConfigs where queryId = $1 and addedVersion >= $2 and COALESCE(removedVersion, $2 - 1) < $2
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type GetQueryConfigParams struct {
|
|
|
|
|
Queryid pgtype.UUID
|
|
|
|
|
Addedversion int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetQueryConfigRow struct {
|
|
|
|
|
ID pgtype.UUID
|
|
|
|
|
Config []byte
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) GetQueryConfig(ctx context.Context, arg GetQueryConfigParams) (GetQueryConfigRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, getQueryConfig, arg.Queryid, arg.Addedversion)
|
|
|
|
|
var i GetQueryConfigRow
|
|
|
|
|
err := row.Scan(&i.ID, &i.Config)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
2025-01-03 13:41:07 +00:00
|
|
|
|
|
|
|
|
const isQueryDeprecated = `-- name: IsQueryDeprecated :one
|
|
|
|
|
SELECT EXISTS (
|
|
|
|
|
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is not null
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (bool, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, isQueryDeprecated, queryid)
|
|
|
|
|
var exists bool
|
|
|
|
|
err := row.Scan(&exists)
|
|
|
|
|
return exists, err
|
|
|
|
|
}
|
2025-01-03 14:08:04 +00:00
|
|
|
|
|
|
|
|
const listQueries = `-- name: ListQueries :many
|
2025-01-03 14:21:14 +00:00
|
|
|
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
2025-01-03 14:08:04 +00:00
|
|
|
FROM queries AS q
|
2025-01-07 16:12:18 +00:00
|
|
|
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
|
|
|
|
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
2025-01-03 14:08:04 +00:00
|
|
|
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
|
2025-01-03 14:21:14 +00:00
|
|
|
Latestversion int32
|
2025-01-03 14:08:04 +00:00
|
|
|
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,
|
2025-01-03 14:21:14 +00:00
|
|
|
&i.Latestversion,
|
2025-01-03 14:08:04 +00:00
|
|
|
&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
|
|
|
|
|
}
|