@@ -11,6 +11,35 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addActiveQueryVersion = `-- name: AddActiveQueryVersion :exec
|
||||
INSERT INTO queryActiveVersions (queryId, versionId) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddActiveQueryVersionParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
}
|
||||
|
||||
// AddActiveQueryVersion
|
||||
//
|
||||
// INSERT INTO queryActiveVersions (queryId, versionId) VALUES ($1, $2)
|
||||
func (q *Queries) AddActiveQueryVersion(ctx context.Context, arg *AddActiveQueryVersionParams) error {
|
||||
_, err := q.db.Exec(ctx, addActiveQueryVersion, arg.Queryid, arg.Versionid)
|
||||
return err
|
||||
}
|
||||
|
||||
const addLatestQueryVersion = `-- name: AddLatestQueryVersion :exec
|
||||
INSERT INTO queryVersions (queryId) VALUES ($1)
|
||||
`
|
||||
|
||||
// AddLatestQueryVersion
|
||||
//
|
||||
// INSERT INTO queryVersions (queryId) VALUES ($1)
|
||||
func (q *Queries) AddLatestQueryVersion(ctx context.Context, queryid pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, addLatestQueryVersion, queryid)
|
||||
return err
|
||||
}
|
||||
|
||||
const addQueryConfig = `-- name: AddQueryConfig :exec
|
||||
INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
|
||||
`
|
||||
@@ -126,14 +155,13 @@ func (q *Queries) GetQueryConfig(ctx context.Context, arg *GetQueryConfigParams)
|
||||
|
||||
const getQueryWithVersion = `-- name: GetQueryWithVersion :one
|
||||
WITH query as (
|
||||
SELECT id, type, activeVersion, latestVersion FROM queries WHERE id = $1
|
||||
SELECT id, type FROM queries WHERE id = $1
|
||||
),
|
||||
config as (
|
||||
SELECT c.queryId, c.config
|
||||
FROM query AS q
|
||||
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
and $2 >= c.addedVersion
|
||||
and (c.removedVersion is null or $2 < c.removedVersion)
|
||||
and isInVersion($2, c.addedVersion, c.removedVersion)
|
||||
),
|
||||
requiredIds as (
|
||||
SELECT r.queryId,
|
||||
@@ -142,16 +170,17 @@ requiredIds as (
|
||||
as requiredIds
|
||||
FROM query AS q
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
and $2 >= r.addedVersion
|
||||
and (r.removedVersion is null or $2 < r.removedVersion)
|
||||
and isInVersion($2, r.addedVersion, r.removedVersion)
|
||||
GROUP BY r.queryId
|
||||
)
|
||||
SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, c.config,
|
||||
SELECT DISTINCT q.id, q.type, coalesce(av.id, 0) as activeVersion, coalesce(lv.id, 0) as latestVersion, c.config,
|
||||
coalesce(
|
||||
r.requiredIds,
|
||||
array[]::uuid[]
|
||||
)::uuid[] as requiredIds
|
||||
FROM query AS q
|
||||
LEFT JOIN queryCurrentActiveVersions as av on q.id = av.queryId
|
||||
LEFT JOIN queryLatestVersions as lv on lv.queryId = q.id
|
||||
LEFT JOIN config AS c ON q.id = c.queryId
|
||||
LEFT JOIN requiredIds AS r ON q.id = r.queryId
|
||||
`
|
||||
@@ -173,14 +202,13 @@ type GetQueryWithVersionRow struct {
|
||||
// GetQueryWithVersion
|
||||
//
|
||||
// WITH query as (
|
||||
// SELECT id, type, activeVersion, latestVersion FROM queries WHERE id = $1
|
||||
// SELECT id, type FROM queries WHERE id = $1
|
||||
// ),
|
||||
// config as (
|
||||
// SELECT c.queryId, c.config
|
||||
// FROM query AS q
|
||||
// LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
// and $2 >= c.addedVersion
|
||||
// and (c.removedVersion is null or $2 < c.removedVersion)
|
||||
// and isInVersion($2, c.addedVersion, c.removedVersion)
|
||||
// ),
|
||||
// requiredIds as (
|
||||
// SELECT r.queryId,
|
||||
@@ -189,16 +217,17 @@ type GetQueryWithVersionRow struct {
|
||||
// as requiredIds
|
||||
// FROM query AS q
|
||||
// LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
// and $2 >= r.addedVersion
|
||||
// and (r.removedVersion is null or $2 < r.removedVersion)
|
||||
// and isInVersion($2, r.addedVersion, r.removedVersion)
|
||||
// GROUP BY r.queryId
|
||||
// )
|
||||
// SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, c.config,
|
||||
// SELECT DISTINCT q.id, q.type, coalesce(av.id, 0) as activeVersion, coalesce(lv.id, 0) as latestVersion, c.config,
|
||||
// coalesce(
|
||||
// r.requiredIds,
|
||||
// array[]::uuid[]
|
||||
// )::uuid[] as requiredIds
|
||||
// FROM query AS q
|
||||
// LEFT JOIN queryCurrentActiveVersions as av on q.id = av.queryId
|
||||
// LEFT JOIN queryLatestVersions as lv on lv.queryId = q.id
|
||||
// LEFT JOIN config AS c ON q.id = c.queryId
|
||||
// LEFT JOIN requiredIds AS r ON q.id = r.queryId
|
||||
func (q *Queries) GetQueryWithVersion(ctx context.Context, arg *GetQueryWithVersionParams) (*GetQueryWithVersionRow, error) {
|
||||
@@ -411,21 +440,3 @@ func (q *Queries) RemoveRequiredQuery(ctx context.Context, arg *RemoveRequiredQu
|
||||
_, 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user