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-20 13:31:48 +00:00
|
|
|
const addQueryConfig = `-- name: AddQueryConfig :exec
|
2025-01-06 12:26:28 +00:00
|
|
|
INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
|
|
|
|
|
`
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
type AddQueryConfigParams struct {
|
2025-01-15 12:19:49 +00:00
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
Config []byte `db:"config"`
|
|
|
|
|
Addedversion int32 `db:"addedversion"`
|
2025-01-06 12:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
// AddQueryConfig
|
2025-01-15 12:19:49 +00:00
|
|
|
//
|
|
|
|
|
// INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
|
2025-01-20 13:31:48 +00:00
|
|
|
func (q *Queries) AddQueryConfig(ctx context.Context, arg *AddQueryConfigParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, addQueryConfig, arg.Queryid, arg.Config, arg.Addedversion)
|
2025-01-06 12:26:28 +00:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
const addRequiredQuery = `-- name: AddRequiredQuery :exec
|
2025-01-06 12:26:28 +00:00
|
|
|
INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3)
|
|
|
|
|
`
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
type AddRequiredQueryParams struct {
|
2025-01-15 12:19:49 +00:00
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
|
|
|
|
Addedversion int32 `db:"addedversion"`
|
2025-01-06 12:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
// AddRequiredQuery
|
2025-01-15 12:19:49 +00:00
|
|
|
//
|
|
|
|
|
// INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3)
|
2025-01-20 13:31:48 +00:00
|
|
|
func (q *Queries) AddRequiredQuery(ctx context.Context, arg *AddRequiredQueryParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, addRequiredQuery, arg.Queryid, arg.Requiredqueryid, arg.Addedversion)
|
2025-01-06 12:26:28 +00:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-20 13:31:48 +00:00
|
|
|
const allQueriesExist = `-- name: AllQueriesExist :one
|
|
|
|
|
SELECT COUNT(*) = COUNT(DISTINCT id) AS all_exist
|
|
|
|
|
FROM unnest($1::uuid[]) AS input_id
|
|
|
|
|
LEFT JOIN queries ON input_id = queries.id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// AllQueriesExist
|
|
|
|
|
//
|
|
|
|
|
// SELECT COUNT(*) = COUNT(DISTINCT id) AS all_exist
|
|
|
|
|
// FROM unnest($1::uuid[]) AS input_id
|
|
|
|
|
// LEFT JOIN queries ON input_id = queries.id
|
|
|
|
|
func (q *Queries) AllQueriesExist(ctx context.Context, dollar_1 []pgtype.UUID) (bool, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, allQueriesExist, dollar_1)
|
|
|
|
|
var all_exist bool
|
|
|
|
|
err := row.Scan(&all_exist)
|
|
|
|
|
return all_exist, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createQuery = `-- name: CreateQuery :one
|
|
|
|
|
INSERT INTO queries (type) VALUES ($1) RETURNING id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// CreateQuery
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
`
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// DeprecateQuery
|
|
|
|
|
//
|
|
|
|
|
// 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-08 18:14:15 +00:00
|
|
|
SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries WHERE id = $1
|
2025-01-03 10:35:42 +00:00
|
|
|
`
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// GetQuery
|
|
|
|
|
//
|
|
|
|
|
// SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries WHERE id = $1
|
|
|
|
|
func (q *Queries) GetQuery(ctx context.Context, id pgtype.UUID) (*Fullactivequery, error) {
|
2025-01-03 10:35:42 +00:00
|
|
|
row := q.db.QueryRow(ctx, getQuery, id)
|
2025-01-08 18:14:15 +00:00
|
|
|
var i Fullactivequery
|
2025-01-03 10:35:42 +00:00
|
|
|
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,
|
|
|
|
|
)
|
2025-01-15 12:19:49 +00:00
|
|
|
return &i, err
|
2025-01-03 10:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
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 {
|
2025-01-15 12:19:49 +00:00
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
Addedversion int32 `db:"addedversion"`
|
2024-12-23 12:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetQueryConfigRow struct {
|
2025-01-15 12:19:49 +00:00
|
|
|
ID pgtype.UUID `db:"id"`
|
|
|
|
|
Config []byte `db:"config"`
|
2024-12-23 12:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// GetQueryConfig
|
|
|
|
|
//
|
|
|
|
|
// SELECT id, config FROM queryConfigs where queryId = $1 and addedVersion >= $2 and COALESCE(removedVersion, $2 - 1) < $2
|
|
|
|
|
func (q *Queries) GetQueryConfig(ctx context.Context, arg *GetQueryConfigParams) (*GetQueryConfigRow, error) {
|
2024-12-23 12:26:05 +00:00
|
|
|
row := q.db.QueryRow(ctx, getQueryConfig, arg.Queryid, arg.Addedversion)
|
|
|
|
|
var i GetQueryConfigRow
|
|
|
|
|
err := row.Scan(&i.ID, &i.Config)
|
2025-01-15 12:19:49 +00:00
|
|
|
return &i, err
|
2024-12-23 12:26:05 +00:00
|
|
|
}
|
2025-01-03 13:41:07 +00:00
|
|
|
|
|
|
|
|
const isQueryDeprecated = `-- name: IsQueryDeprecated :one
|
|
|
|
|
SELECT EXISTS (
|
2025-01-08 18:14:15 +00:00
|
|
|
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is null LIMIT 1
|
2025-01-03 13:41:07 +00:00
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// IsQueryDeprecated
|
|
|
|
|
//
|
|
|
|
|
// SELECT EXISTS (
|
|
|
|
|
// SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is null LIMIT 1
|
|
|
|
|
// )
|
2025-01-03 13:41:07 +00:00
|
|
|
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-08 18:14:15 +00:00
|
|
|
SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries
|
2025-01-03 14:08:04 +00:00
|
|
|
`
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// ListQueries
|
|
|
|
|
//
|
|
|
|
|
// SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries
|
|
|
|
|
func (q *Queries) ListQueries(ctx context.Context) ([]*Fullactivequery, error) {
|
2025-01-03 14:08:04 +00:00
|
|
|
rows, err := q.db.Query(ctx, listQueries)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
2025-01-15 12:19:49 +00:00
|
|
|
items := []*Fullactivequery{}
|
2025-01-03 14:08:04 +00:00
|
|
|
for rows.Next() {
|
2025-01-08 18:14:15 +00:00
|
|
|
var i Fullactivequery
|
2025-01-03 14:08:04 +00:00
|
|
|
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
|
|
|
|
|
}
|
2025-01-15 12:19:49 +00:00
|
|
|
items = append(items, &i)
|
2025-01-03 14:08:04 +00:00
|
|
|
}
|
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return items, nil
|
|
|
|
|
}
|
2025-01-20 13:31:48 +00:00
|
|
|
|
|
|
|
|
const removeQueryConfig = `-- name: RemoveQueryConfig :exec
|
|
|
|
|
UPDATE queryConfigs SET removedVersion = $1 WHERE queryId = $2 and removedVersion is null
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type RemoveQueryConfigParams struct {
|
|
|
|
|
Removedversion *int32 `db:"removedversion"`
|
|
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoveQueryConfig
|
|
|
|
|
//
|
|
|
|
|
// UPDATE queryConfigs SET removedVersion = $1 WHERE queryId = $2 and removedVersion is null
|
|
|
|
|
func (q *Queries) RemoveQueryConfig(ctx context.Context, arg *RemoveQueryConfigParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, removeQueryConfig, arg.Removedversion, arg.Queryid)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const removeRequiredQuery = `-- name: RemoveRequiredQuery :exec
|
|
|
|
|
UPDATE requiredQueries SET removedVersion = $1 WHERE requiredQueryId = $2 and queryId = $3 and removedVersion is null
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type RemoveRequiredQueryParams struct {
|
|
|
|
|
Removedversion *int32 `db:"removedversion"`
|
|
|
|
|
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
|
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoveRequiredQuery
|
|
|
|
|
//
|
|
|
|
|
// UPDATE requiredQueries SET removedVersion = $1 WHERE requiredQueryId = $2 and queryId = $3 and removedVersion is null
|
|
|
|
|
func (q *Queries) RemoveRequiredQuery(ctx context.Context, arg *RemoveRequiredQueryParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, removeRequiredQuery, arg.Removedversion, arg.Requiredqueryid, arg.Queryid)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateQuery = `-- name: UpdateQuery :exec
|
|
|
|
|
UPDATE queries SET activeVersion = $1, latestVersion = $2 WHERE id = $3
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type UpdateQueryParams struct {
|
|
|
|
|
Activeversion int32 `db:"activeversion"`
|
|
|
|
|
Latestversion int32 `db:"latestversion"`
|
|
|
|
|
ID pgtype.UUID `db:"id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateQuery
|
|
|
|
|
//
|
|
|
|
|
// UPDATE queries SET activeVersion = $1, latestVersion = $2 WHERE id = $3
|
|
|
|
|
func (q *Queries) UpdateQuery(ctx context.Context, arg *UpdateQueryParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, updateQuery, arg.Activeversion, arg.Latestversion, arg.ID)
|
|
|
|
|
return err
|
|
|
|
|
}
|