2024-12-19 18:49:22 +00:00
|
|
|
// 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"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
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
|
2024-12-20 17:35:33 +00:00
|
|
|
`
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
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
|
2025-02-11 15:22:59 +00:00
|
|
|
WITH reqQueries as (
|
|
|
|
|
SELECT q.id as queryId, q.activeVersion, q.type
|
2025-01-29 11:52:37 +00:00
|
|
|
FROM requiredQueries as rq
|
|
|
|
|
JOIN queries as q on q.id = rq.requiredQueryId
|
2025-02-11 15:22:59 +00:00
|
|
|
WHERE rq.queryId = $2
|
|
|
|
|
and $3 >= rq.addedVersion
|
|
|
|
|
and (rq.removedVersion is null or $3 < rq.removedVersion)
|
|
|
|
|
),
|
|
|
|
|
codeVersions as (
|
|
|
|
|
SELECT
|
|
|
|
|
d.id as documentId,
|
|
|
|
|
coalesce(ccv.minCleanVersion, 1) as minCleanVersion,
|
|
|
|
|
coalesce(ccv.minTextVersion, 1) as minTextVersion
|
|
|
|
|
FROM documents as d
|
|
|
|
|
LEFT JOIN collectors as c on c.jobId = d.jobId
|
|
|
|
|
LEFT JOIN collectorCodeVersions as ccv on c.id = ccv.collectorId
|
|
|
|
|
and c.activeVersion >= ccv.addedVersion
|
|
|
|
|
and c.activeVersion < COALESCE(ccv.removedVersion, c.activeVersion)
|
|
|
|
|
WHERE d.id = $1
|
|
|
|
|
LIMIT 1
|
|
|
|
|
),
|
|
|
|
|
latestVersions AS (
|
|
|
|
|
SELECT
|
|
|
|
|
rq.queryId,
|
|
|
|
|
rq.type,
|
|
|
|
|
r.queryVersion,
|
|
|
|
|
r.cleanVersion,
|
|
|
|
|
r.textVersion,
|
|
|
|
|
ROW_NUMBER() OVER (
|
|
|
|
|
PARTITION BY rq.queryId
|
|
|
|
|
ORDER BY r.cleanVersion DESC, r.textVersion DESC
|
|
|
|
|
) as rowNumber
|
|
|
|
|
FROM reqQueries as rq
|
|
|
|
|
LEFT JOIN results as r ON rq.queryId = r.queryId
|
|
|
|
|
and r.documentId = $1
|
|
|
|
|
JOIN codeVersions as ccv on ccv.documentId = r.documentId
|
|
|
|
|
WHERE r.documentId = $1
|
|
|
|
|
and r.queryVersion = rq.activeVersion
|
|
|
|
|
and r.cleanVersion >= ccv.minCleanVersion
|
|
|
|
|
and r.textVersion >= ccv.minTextVersion
|
|
|
|
|
)
|
|
|
|
|
SELECT lv.queryId, lv.type, r.value
|
|
|
|
|
FROM latestVersions as lv
|
|
|
|
|
JOIN results as r ON r.queryId = lv.queryId
|
|
|
|
|
and r.documentId = $1
|
|
|
|
|
and r.queryVersion = lv.queryVersion
|
|
|
|
|
and r.cleanVersion = lv.cleanVersion
|
|
|
|
|
and r.textVersion = lv.textVersion
|
|
|
|
|
and lv.rowNumber = 1
|
2025-01-29 11:52:37 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type ListQueryRequirementValuesParams struct {
|
2025-02-11 15:22:59 +00:00
|
|
|
Documentid pgtype.UUID `db:"documentid"`
|
|
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
|
|
|
|
Version int32 `db:"version"`
|
2025-01-29 11:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListQueryRequirementValuesRow struct {
|
2025-01-15 12:19:49 +00:00
|
|
|
Queryid pgtype.UUID `db:"queryid"`
|
2025-01-29 11:52:37 +00:00
|
|
|
Type Querytype `db:"type"`
|
2025-02-11 15:22:59 +00:00
|
|
|
Value string `db:"value"`
|
2024-12-20 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
// ListQueryRequirementValues
|
2025-01-15 12:19:49 +00:00
|
|
|
//
|
2025-02-11 15:22:59 +00:00
|
|
|
// WITH reqQueries as (
|
|
|
|
|
// SELECT q.id as queryId, q.activeVersion, q.type
|
2025-01-29 11:52:37 +00:00
|
|
|
// FROM requiredQueries as rq
|
|
|
|
|
// JOIN queries as q on q.id = rq.requiredQueryId
|
2025-02-11 15:22:59 +00:00
|
|
|
// WHERE rq.queryId = $2
|
|
|
|
|
// and $3 >= rq.addedVersion
|
|
|
|
|
// and (rq.removedVersion is null or $3 < rq.removedVersion)
|
|
|
|
|
// ),
|
|
|
|
|
// codeVersions as (
|
|
|
|
|
// SELECT
|
|
|
|
|
// d.id as documentId,
|
|
|
|
|
// coalesce(ccv.minCleanVersion, 1) as minCleanVersion,
|
|
|
|
|
// coalesce(ccv.minTextVersion, 1) as minTextVersion
|
|
|
|
|
// FROM documents as d
|
|
|
|
|
// LEFT JOIN collectors as c on c.jobId = d.jobId
|
|
|
|
|
// LEFT JOIN collectorCodeVersions as ccv on c.id = ccv.collectorId
|
|
|
|
|
// and c.activeVersion >= ccv.addedVersion
|
|
|
|
|
// and c.activeVersion < COALESCE(ccv.removedVersion, c.activeVersion)
|
|
|
|
|
// WHERE d.id = $1
|
|
|
|
|
// LIMIT 1
|
|
|
|
|
// ),
|
|
|
|
|
// latestVersions AS (
|
|
|
|
|
// SELECT
|
|
|
|
|
// rq.queryId,
|
|
|
|
|
// rq.type,
|
|
|
|
|
// r.queryVersion,
|
|
|
|
|
// r.cleanVersion,
|
|
|
|
|
// r.textVersion,
|
|
|
|
|
// ROW_NUMBER() OVER (
|
|
|
|
|
// PARTITION BY rq.queryId
|
|
|
|
|
// ORDER BY r.cleanVersion DESC, r.textVersion DESC
|
|
|
|
|
// ) as rowNumber
|
|
|
|
|
// FROM reqQueries as rq
|
|
|
|
|
// LEFT JOIN results as r ON rq.queryId = r.queryId
|
|
|
|
|
// and r.documentId = $1
|
|
|
|
|
// JOIN codeVersions as ccv on ccv.documentId = r.documentId
|
|
|
|
|
// WHERE r.documentId = $1
|
|
|
|
|
// and r.queryVersion = rq.activeVersion
|
|
|
|
|
// and r.cleanVersion >= ccv.minCleanVersion
|
|
|
|
|
// and r.textVersion >= ccv.minTextVersion
|
|
|
|
|
// )
|
|
|
|
|
// SELECT lv.queryId, lv.type, r.value
|
|
|
|
|
// FROM latestVersions as lv
|
|
|
|
|
// JOIN results as r ON r.queryId = lv.queryId
|
|
|
|
|
// and r.documentId = $1
|
|
|
|
|
// and r.queryVersion = lv.queryVersion
|
|
|
|
|
// and r.cleanVersion = lv.cleanVersion
|
|
|
|
|
// and r.textVersion = lv.textVersion
|
|
|
|
|
// and lv.rowNumber = 1
|
2025-01-29 11:52:37 +00:00
|
|
|
func (q *Queries) ListQueryRequirementValues(ctx context.Context, arg *ListQueryRequirementValuesParams) ([]*ListQueryRequirementValuesRow, error) {
|
2025-02-11 15:22:59 +00:00
|
|
|
rows, err := q.db.Query(ctx, listQueryRequirementValues, arg.Documentid, arg.Queryid, arg.Version)
|
2024-12-20 17:35:33 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
2025-01-29 11:52:37 +00:00
|
|
|
items := []*ListQueryRequirementValuesRow{}
|
2024-12-20 17:35:33 +00:00
|
|
|
for rows.Next() {
|
2025-01-29 11:52:37 +00:00
|
|
|
var i ListQueryRequirementValuesRow
|
2025-02-11 15:22:59 +00:00
|
|
|
if err := rows.Scan(&i.Queryid, &i.Type, &i.Value); err != nil {
|
2024-12-20 17:35:33 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-01-15 12:19:49 +00:00
|
|
|
items = append(items, &i)
|
2024-12-20 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return items, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
const listUnsyncedNoDepsQueriesByDocId = `-- name: ListUnsyncedNoDepsQueriesByDocId :many
|
|
|
|
|
WITH docs as (
|
|
|
|
|
SELECT id, jobId from documents where id = $1
|
|
|
|
|
),
|
|
|
|
|
unsyncedQueries AS (
|
|
|
|
|
SELECT DISTINCT dt.queryId, dt.requiredIds, r.value, d.jobID, d.id
|
|
|
|
|
from docs as d
|
|
|
|
|
JOIN collectorQueryDependencyTree as dt on d.jobId = dt.jobId
|
|
|
|
|
JOIN fullActiveCollectors as c on c.id = dt.collectorId
|
2025-01-29 11:52:37 +00:00
|
|
|
LEFT JOIN results as r on r.queryId = dt.queryId
|
2025-02-11 15:22:59 +00:00
|
|
|
and r.documentId = d.id
|
2025-01-29 11:52:37 +00:00
|
|
|
and r.queryVersion = dt.queryVersion
|
|
|
|
|
and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
2025-02-11 15:22:59 +00:00
|
|
|
where r.value is null
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
2025-02-11 15:22:59 +00:00
|
|
|
SELECT DISTINCT queryId FROM unsyncedQueries as baseuq
|
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
|
SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds)
|
|
|
|
|
)
|
2025-01-29 11:52:37 +00:00
|
|
|
`
|
2024-12-19 18:49:22 +00:00
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
// ListUnsyncedNoDepsQueriesByDocId
|
2025-01-29 11:52:37 +00:00
|
|
|
//
|
2025-02-11 15:22:59 +00:00
|
|
|
// WITH docs as (
|
|
|
|
|
// SELECT id, jobId from documents where id = $1
|
|
|
|
|
// ),
|
|
|
|
|
// unsyncedQueries AS (
|
|
|
|
|
// SELECT DISTINCT dt.queryId, dt.requiredIds, r.value, d.jobID, d.id
|
|
|
|
|
// from docs as d
|
|
|
|
|
// JOIN collectorQueryDependencyTree as dt on d.jobId = dt.jobId
|
|
|
|
|
// JOIN fullActiveCollectors as c on c.id = dt.collectorId
|
2025-01-29 11:52:37 +00:00
|
|
|
// LEFT JOIN results as r on r.queryId = dt.queryId
|
2025-02-11 15:22:59 +00:00
|
|
|
// and r.documentId = d.id
|
2025-01-29 11:52:37 +00:00
|
|
|
// and r.queryVersion = dt.queryVersion
|
|
|
|
|
// and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
2025-02-11 15:22:59 +00:00
|
|
|
// where r.value is null
|
2025-01-29 11:52:37 +00:00
|
|
|
// )
|
2025-02-11 15:22:59 +00:00
|
|
|
// SELECT DISTINCT queryId FROM unsyncedQueries as baseuq
|
|
|
|
|
// WHERE NOT EXISTS (
|
|
|
|
|
// SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds)
|
|
|
|
|
// )
|
|
|
|
|
func (q *Queries) ListUnsyncedNoDepsQueriesByDocId(ctx context.Context, dollar_1 pgtype.UUID) ([]pgtype.UUID, error) {
|
|
|
|
|
rows, err := q.db.Query(ctx, listUnsyncedNoDepsQueriesByDocId, dollar_1)
|
2024-12-19 18:49:22 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
2025-02-11 15:22:59 +00:00
|
|
|
items := []pgtype.UUID{}
|
2024-12-19 18:49:22 +00:00
|
|
|
for rows.Next() {
|
2025-02-11 15:22:59 +00:00
|
|
|
var queryid pgtype.UUID
|
|
|
|
|
if err := rows.Scan(&queryid); err != nil {
|
2024-12-19 18:49:22 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-02-11 15:22:59 +00:00
|
|
|
items = append(items, queryid)
|
2024-12-19 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return items, nil
|
|
|
|
|
}
|
2024-12-20 17:35:33 +00:00
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
const setResult = `-- name: SetResult :exec
|
|
|
|
|
INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6)
|
2024-12-20 17:35:33 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type SetResultParams struct {
|
2025-01-15 12:19:49 +00:00
|
|
|
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"`
|
2024-12-20 17:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-15 12:19:49 +00:00
|
|
|
// SetResult
|
|
|
|
|
//
|
2025-02-11 15:22:59 +00:00
|
|
|
// INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6)
|
|
|
|
|
func (q *Queries) SetResult(ctx context.Context, arg *SetResultParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, setResult,
|
2024-12-20 17:35:33 +00:00
|
|
|
arg.Queryid,
|
|
|
|
|
arg.Documentid,
|
|
|
|
|
arg.Value,
|
|
|
|
|
arg.Cleanversion,
|
|
|
|
|
arg.Textversion,
|
|
|
|
|
arg.Queryversion,
|
|
|
|
|
)
|
2025-02-11 15:22:59 +00:00
|
|
|
return err
|
2024-12-20 17:35:33 +00:00
|
|
|
}
|