Files
query-orchestration/internal/database/repository/query.sql.go
T
Michael McGuinness 788b21594c creatorupdatordeprecate
2025-01-07 13:54:41 +00:00

101 lines
2.6 KiB
Go

// 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"
)
const deprecateQuery = `-- name: DeprecateQuery :exec
INSERT INTO queryDeprecations (queryId) VALUES ($1) RETURNING id
`
func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error {
_, err := q.db.Exec(ctx, deprecateQuery, queryid)
return err
}
const getQuery = `-- 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
GROUP BY q.id, c.config
`
type GetQueryRow struct {
ID pgtype.UUID
Type Querytype
Activeversion int32
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,
&i.Config,
&i.Requiredids,
)
return i, err
}
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
}
const getQueryType = `-- name: GetQueryType :one
SELECT type FROM queries where id = $1
`
func (q *Queries) GetQueryType(ctx context.Context, id pgtype.UUID) (Querytype, error) {
row := q.db.QueryRow(ctx, getQueryType, id)
var type_ Querytype
err := row.Scan(&type_)
return type_, err
}
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
}