Merged in feature/testquery (pull request #39)

Test Query

* depstextandclean

* startedcleaningresult

* resulttidyup

* roundone

* cleaning

* unsyncedquery

* startedtestsandsimplification

* api

* querytests

* resultprocessortests

* unittests

* cleanup
This commit is contained in:
Michael McGuinness
2025-01-29 11:52:37 +00:00
parent c36b0cdcf8
commit 0ac5ff9e15
109 changed files with 2804 additions and 2100 deletions
+87
View File
@@ -124,6 +124,59 @@ func (q *Queries) GetQueryConfig(ctx context.Context, arg *GetQueryConfigParams)
return &i, err
}
const getQueryWithVersion = `-- name: GetQueryWithVersion :one
SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, coalesce(c.config, null) as config, ARRAY_AGG(DISTINCT r.requiredQueryId)::uuid[] as requiredIds
FROM queries AS q
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
and $2 >= c.addedVersion
and $2 < COALESCE(c.removedVersion, $2 + 1)
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
and $2 >= r.addedVersion
and $2 < COALESCE(r.removedVersion, $2 + 1)
WHERE q.id = $1
GROUP BY q.id, q.type, q.activeversion, q.latestversion, c.config
`
type GetQueryWithVersionParams struct {
ID pgtype.UUID `db:"id"`
Addedversion int32 `db:"addedversion"`
}
type GetQueryWithVersionRow struct {
ID pgtype.UUID `db:"id"`
Type Querytype `db:"type"`
Activeversion int32 `db:"activeversion"`
Latestversion int32 `db:"latestversion"`
Config []byte `db:"config"`
Requiredids []pgtype.UUID `db:"requiredids"`
}
// GetQueryWithVersion
//
// SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, coalesce(c.config, null) as config, ARRAY_AGG(DISTINCT r.requiredQueryId)::uuid[] as requiredIds
// FROM queries AS q
// LEFT JOIN queryConfigs AS c ON q.id = c.queryId
// and $2 >= c.addedVersion
// and $2 < COALESCE(c.removedVersion, $2 + 1)
// LEFT JOIN requiredQueries AS r ON q.id = r.queryId
// and $2 >= r.addedVersion
// and $2 < COALESCE(r.removedVersion, $2 + 1)
// WHERE q.id = $1
// GROUP BY q.id, q.type, q.activeversion, q.latestversion, c.config
func (q *Queries) GetQueryWithVersion(ctx context.Context, arg *GetQueryWithVersionParams) (*GetQueryWithVersionRow, error) {
row := q.db.QueryRow(ctx, getQueryWithVersion, arg.ID, arg.Addedversion)
var i GetQueryWithVersionRow
err := row.Scan(
&i.ID,
&i.Type,
&i.Activeversion,
&i.Latestversion,
&i.Config,
&i.Requiredids,
)
return &i, err
}
const isQueryInDependencyTree = `-- name: IsQueryInDependencyTree :one
SELECT EXISTS (
SELECT 1 FROM queryActiveDependencies WHERE id = any($1) and requiredQueryId = $2 or $2 = any($1)
@@ -181,6 +234,40 @@ func (q *Queries) ListQueries(ctx context.Context) ([]*Fullactivequery, error) {
return items, nil
}
const listQueriesById = `-- name: ListQueriesById :many
SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries WHERE id = any($1)
`
// ListQueriesById
//
// SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries WHERE id = any($1)
func (q *Queries) ListQueriesById(ctx context.Context, id []pgtype.UUID) ([]*Fullactivequery, error) {
rows, err := q.db.Query(ctx, listQueriesById, id)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*Fullactivequery{}
for rows.Next() {
var i Fullactivequery
if err := rows.Scan(
&i.ID,
&i.Type,
&i.Activeversion,
&i.Latestversion,
&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
}
const removeQueryConfig = `-- name: RemoveQueryConfig :exec
UPDATE queryConfigs SET removedVersion = $1 WHERE queryId = $2 and removedVersion is null
`