0ac5ff9e15
Test Query * depstextandclean * startedcleaningresult * resulttidyup * roundone * cleaning * unsyncedquery * startedtestsandsimplification * api * querytests * resultprocessortests * unittests * cleanup
233 lines
7.3 KiB
Go
233 lines
7.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: result.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getResultValueWithVersion = `-- name: GetResultValueWithVersion :one
|
|
SELECT id, value FROM results WHERE queryId = $1 and queryVersion = $2 and documentId = $3 and cleanVersion >= $4 and textVersion >= $5
|
|
`
|
|
|
|
type GetResultValueWithVersionParams struct {
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
Queryversion int32 `db:"queryversion"`
|
|
Documentid pgtype.UUID `db:"documentid"`
|
|
Cleanversion int32 `db:"cleanversion"`
|
|
Textversion int32 `db:"textversion"`
|
|
}
|
|
|
|
type GetResultValueWithVersionRow struct {
|
|
ID pgtype.UUID `db:"id"`
|
|
Value string `db:"value"`
|
|
}
|
|
|
|
// GetResultValueWithVersion
|
|
//
|
|
// SELECT id, value FROM results WHERE queryId = $1 and queryVersion = $2 and documentId = $3 and cleanVersion >= $4 and textVersion >= $5
|
|
func (q *Queries) GetResultValueWithVersion(ctx context.Context, arg *GetResultValueWithVersionParams) (*GetResultValueWithVersionRow, error) {
|
|
row := q.db.QueryRow(ctx, getResultValueWithVersion,
|
|
arg.Queryid,
|
|
arg.Queryversion,
|
|
arg.Documentid,
|
|
arg.Cleanversion,
|
|
arg.Textversion,
|
|
)
|
|
var i GetResultValueWithVersionRow
|
|
err := row.Scan(&i.ID, &i.Value)
|
|
return &i, err
|
|
}
|
|
|
|
const listQueryRequirementValues = `-- name: ListQueryRequirementValues :many
|
|
WITH latest_versions AS (
|
|
SELECT
|
|
r.queryId,
|
|
MAX(r.cleanVersion) as max_clean_version,
|
|
MAX(r.textVersion) as max_text_version
|
|
FROM results r
|
|
WHERE r.documentId = $3
|
|
AND r.queryVersion = $2
|
|
GROUP BY r.queryId
|
|
)
|
|
SELECT rq.requiredQueryId as queryId, r.value, q.type
|
|
FROM requiredQueries as rq
|
|
JOIN results as r on r.queryId = rq.requiredQueryId
|
|
JOIN queries as q on q.id = rq.requiredQueryId
|
|
JOIN latest_versions lv ON lv.queryId = r.queryId
|
|
WHERE rq.queryId = $1 and r.documentId = $3
|
|
and $2 >= rq.addedVersion
|
|
and $2 < COALESCE(rq.removedVersion, $2 + 1)
|
|
and r.queryVersion = $2
|
|
and r.cleanVersion >= $4 and r.textVersion >= $5
|
|
AND r.cleanVersion = lv.max_clean_version
|
|
AND r.textVersion = lv.max_text_version
|
|
`
|
|
|
|
type ListQueryRequirementValuesParams struct {
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
Addedversion int32 `db:"addedversion"`
|
|
Documentid pgtype.UUID `db:"documentid"`
|
|
Cleanversion int32 `db:"cleanversion"`
|
|
Textversion int32 `db:"textversion"`
|
|
}
|
|
|
|
type ListQueryRequirementValuesRow struct {
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
Value string `db:"value"`
|
|
Type Querytype `db:"type"`
|
|
}
|
|
|
|
// ListQueryRequirementValues
|
|
//
|
|
// WITH latest_versions AS (
|
|
// SELECT
|
|
// r.queryId,
|
|
// MAX(r.cleanVersion) as max_clean_version,
|
|
// MAX(r.textVersion) as max_text_version
|
|
// FROM results r
|
|
// WHERE r.documentId = $3
|
|
// AND r.queryVersion = $2
|
|
// GROUP BY r.queryId
|
|
// )
|
|
// SELECT rq.requiredQueryId as queryId, r.value, q.type
|
|
// FROM requiredQueries as rq
|
|
// JOIN results as r on r.queryId = rq.requiredQueryId
|
|
// JOIN queries as q on q.id = rq.requiredQueryId
|
|
// JOIN latest_versions lv ON lv.queryId = r.queryId
|
|
// WHERE rq.queryId = $1 and r.documentId = $3
|
|
// and $2 >= rq.addedVersion
|
|
// and $2 < COALESCE(rq.removedVersion, $2 + 1)
|
|
// and r.queryVersion = $2
|
|
// and r.cleanVersion >= $4 and r.textVersion >= $5
|
|
// AND r.cleanVersion = lv.max_clean_version
|
|
// AND r.textVersion = lv.max_text_version
|
|
func (q *Queries) ListQueryRequirementValues(ctx context.Context, arg *ListQueryRequirementValuesParams) ([]*ListQueryRequirementValuesRow, error) {
|
|
rows, err := q.db.Query(ctx, listQueryRequirementValues,
|
|
arg.Queryid,
|
|
arg.Addedversion,
|
|
arg.Documentid,
|
|
arg.Cleanversion,
|
|
arg.Textversion,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*ListQueryRequirementValuesRow{}
|
|
for rows.Next() {
|
|
var i ListQueryRequirementValuesRow
|
|
if err := rows.Scan(&i.Queryid, &i.Value, &i.Type); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listUnsyncedQueriesByDocId = `-- name: ListUnsyncedQueriesByDocId :many
|
|
WITH RECURSIVE unsyncedQueries AS (
|
|
SELECT dt.queryId, dt.requiredIds
|
|
from documents as d
|
|
JOIN fullActiveCollectors as c on d.jobId = c.jobId
|
|
JOIN collectorQueryDependencyTree as dt on c.id = dt.collectorId
|
|
LEFT JOIN results as r on r.queryId = dt.queryId
|
|
and r.queryVersion = dt.queryVersion
|
|
and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
|
where d.id = $1 and r.value is null
|
|
|
|
UNION
|
|
|
|
SELECT DISTINCT dt.queryId, dt.requiredIds
|
|
FROM unsyncedQueries as u
|
|
JOIN collectorQueryDependencyTree as dt ON u.queryId = any(dt.requiredIds)
|
|
)
|
|
SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries
|
|
WHERE id in (SELECT queryId FROM unsyncedQueries)
|
|
`
|
|
|
|
// ListUnsyncedQueriesByDocId
|
|
//
|
|
// WITH RECURSIVE unsyncedQueries AS (
|
|
// SELECT dt.queryId, dt.requiredIds
|
|
// from documents as d
|
|
// JOIN fullActiveCollectors as c on d.jobId = c.jobId
|
|
// JOIN collectorQueryDependencyTree as dt on c.id = dt.collectorId
|
|
// LEFT JOIN results as r on r.queryId = dt.queryId
|
|
// and r.queryVersion = dt.queryVersion
|
|
// and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
|
// where d.id = $1 and r.value is null
|
|
//
|
|
// UNION
|
|
//
|
|
// SELECT DISTINCT dt.queryId, dt.requiredIds
|
|
// FROM unsyncedQueries as u
|
|
// JOIN collectorQueryDependencyTree as dt ON u.queryId = any(dt.requiredIds)
|
|
// )
|
|
// SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries
|
|
// WHERE id in (SELECT queryId FROM unsyncedQueries)
|
|
func (q *Queries) ListUnsyncedQueriesByDocId(ctx context.Context, id pgtype.UUID) ([]*Fullactivequery, error) {
|
|
rows, err := q.db.Query(ctx, listUnsyncedQueriesByDocId, 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 setResult = `-- name: SetResult :one
|
|
INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id
|
|
`
|
|
|
|
type SetResultParams struct {
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
Documentid pgtype.UUID `db:"documentid"`
|
|
Value string `db:"value"`
|
|
Cleanversion int32 `db:"cleanversion"`
|
|
Textversion int32 `db:"textversion"`
|
|
Queryversion int32 `db:"queryversion"`
|
|
}
|
|
|
|
// SetResult
|
|
//
|
|
// INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id
|
|
func (q *Queries) SetResult(ctx context.Context, arg *SetResultParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, setResult,
|
|
arg.Queryid,
|
|
arg.Documentid,
|
|
arg.Value,
|
|
arg.Cleanversion,
|
|
arg.Textversion,
|
|
arg.Queryversion,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|