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:
@@ -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
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user