Files
query-orchestration/internal/database/repository/query.sql.go
T

172 lines
4.7 KiB
Go
Raw Normal View History

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
`
// CreateQuery
//
// INSERT INTO queries (type) VALUES ($1) RETURNING id
2025-01-06 12:26:28 +00:00
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 `db:"queryid"`
Config []byte `db:"config"`
Addedversion int32 `db:"addedversion"`
2025-01-06 12:26:28 +00:00
}
// CreateQueryConfig
//
// INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
func (q *Queries) CreateQueryConfig(ctx context.Context, arg *CreateQueryConfigParams) error {
2025-01-06 12:26:28 +00:00
_, 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 `db:"queryid"`
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
Addedversion int32 `db:"addedversion"`
2025-01-06 12:26:28 +00:00
}
// CreateRequiredQuery
//
// INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3)
func (q *Queries) CreateRequiredQuery(ctx context.Context, arg *CreateRequiredQueryParams) error {
2025-01-06 12:26:28 +00:00
_, 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
`
// 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
SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries WHERE id = $1
2025-01-03 10:35:42 +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)
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,
)
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 {
Queryid pgtype.UUID `db:"queryid"`
Addedversion int32 `db:"addedversion"`
2024-12-23 12:26:05 +00:00
}
type GetQueryConfigRow struct {
ID pgtype.UUID `db:"id"`
Config []byte `db:"config"`
2024-12-23 12:26:05 +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)
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 (
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is null LIMIT 1
2025-01-03 13:41:07 +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
SELECT id, type, activeVersion, latestVersion, config, requiredIds FROM fullActiveQueries
2025-01-03 14:08:04 +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()
items := []*Fullactivequery{}
2025-01-03 14:08:04 +00:00
for rows.Next() {
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
}
items = append(items, &i)
2025-01-03 14:08:04 +00:00
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}