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"
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
"github.com/google/uuid"
|
2024-12-19 18:49:22 +00:00
|
|
|
)
|
|
|
|
|
|
2025-02-20 19:02:44 +00:00
|
|
|
const addResult = `-- name: AddResult :one
|
|
|
|
|
INSERT INTO results (queryId, value, textEntryId, queryVersion) VALUES ($1, $2, $3, $4) returning id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type AddResultParams struct {
|
2025-03-20 11:06:41 +00:00
|
|
|
Queryid uuid.UUID `db:"queryid"`
|
|
|
|
|
Value string `db:"value"`
|
|
|
|
|
Textentryid uuid.UUID `db:"textentryid"`
|
|
|
|
|
Queryversion int32 `db:"queryversion"`
|
2025-02-20 19:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddResult
|
|
|
|
|
//
|
|
|
|
|
// INSERT INTO results (queryId, value, textEntryId, queryVersion) VALUES ($1, $2, $3, $4) returning id
|
2025-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) AddResult(ctx context.Context, arg *AddResultParams) (uuid.UUID, error) {
|
2025-02-20 19:02:44 +00:00
|
|
|
row := q.db.QueryRow(ctx, addResult,
|
|
|
|
|
arg.Queryid,
|
|
|
|
|
arg.Value,
|
|
|
|
|
arg.Textentryid,
|
|
|
|
|
arg.Queryversion,
|
|
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
var id uuid.UUID
|
2025-02-20 19:02:44 +00:00
|
|
|
err := row.Scan(&id)
|
|
|
|
|
return id, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addResultDependency = `-- name: AddResultDependency :exec
|
|
|
|
|
INSERT INTO resultDependencies (resultId, requiredResultId) VALUES ($1, $2)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type AddResultDependencyParams struct {
|
2025-03-20 11:06:41 +00:00
|
|
|
Resultid uuid.UUID `db:"resultid"`
|
|
|
|
|
Requiredresultid uuid.UUID `db:"requiredresultid"`
|
2025-02-20 19:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddResultDependency
|
|
|
|
|
//
|
|
|
|
|
// INSERT INTO resultDependencies (resultId, requiredResultId) VALUES ($1, $2)
|
|
|
|
|
func (q *Queries) AddResultDependency(ctx context.Context, arg *AddResultDependencyParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, addResultDependency, arg.Resultid, arg.Requiredresultid)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
const getResultValueWithVersion = `-- name: GetResultValueWithVersion :one
|
2025-02-20 19:02:44 +00:00
|
|
|
WITH doc as (
|
2025-03-10 11:03:00 +00:00
|
|
|
SELECT id, clientId
|
2025-02-20 19:02:44 +00:00
|
|
|
FROM documents
|
|
|
|
|
WHERE id = $3
|
|
|
|
|
)
|
|
|
|
|
SELECT r.id, r.value
|
|
|
|
|
FROM doc as d
|
|
|
|
|
JOIN currentTextEntries as cte on cte.documentId = d.id
|
|
|
|
|
LEFT JOIN results as r
|
|
|
|
|
on r.queryId = $1
|
|
|
|
|
and r.queryVersion = $2
|
|
|
|
|
and r.textEntryId = cte.id
|
2024-12-20 17:35:33 +00:00
|
|
|
`
|
|
|
|
|
|
2025-01-29 11:52:37 +00:00
|
|
|
type GetResultValueWithVersionParams struct {
|
2025-03-20 11:06:41 +00:00
|
|
|
Queryid *uuid.UUID `db:"queryid"`
|
|
|
|
|
Queryversion *int32 `db:"queryversion"`
|
|
|
|
|
Documentid *uuid.UUID `db:"documentid"`
|
2025-01-29 11:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetResultValueWithVersionRow struct {
|
2025-03-20 11:06:41 +00:00
|
|
|
ID *uuid.UUID `db:"id"`
|
|
|
|
|
Value *string `db:"value"`
|
2025-01-29 11:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetResultValueWithVersion
|
|
|
|
|
//
|
2025-02-20 19:02:44 +00:00
|
|
|
// WITH doc as (
|
2025-03-10 11:03:00 +00:00
|
|
|
// SELECT id, clientId
|
2025-02-20 19:02:44 +00:00
|
|
|
// FROM documents
|
|
|
|
|
// WHERE id = $3
|
|
|
|
|
// )
|
|
|
|
|
// SELECT r.id, r.value
|
|
|
|
|
// FROM doc as d
|
|
|
|
|
// JOIN currentTextEntries as cte on cte.documentId = d.id
|
|
|
|
|
// LEFT JOIN results as r
|
|
|
|
|
// on r.queryId = $1
|
|
|
|
|
// and r.queryVersion = $2
|
|
|
|
|
// and r.textEntryId = cte.id
|
2025-01-29 11:52:37 +00:00
|
|
|
func (q *Queries) GetResultValueWithVersion(ctx context.Context, arg *GetResultValueWithVersionParams) (*GetResultValueWithVersionRow, error) {
|
2025-02-20 19:02:44 +00:00
|
|
|
row := q.db.QueryRow(ctx, getResultValueWithVersion, arg.Queryid, arg.Queryversion, arg.Documentid)
|
2025-01-29 11:52:37 +00:00
|
|
|
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 (
|
2025-05-05 09:31:21 +00:00
|
|
|
SELECT av.queryId, av.activeVersion, q.queryType
|
2025-01-29 11:52:37 +00:00
|
|
|
FROM requiredQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN queryCurrentActiveVersions as av on av.queryId = rq.requiredQueryId
|
2025-05-05 09:31:21 +00:00
|
|
|
JOIN queries as q on q.queryId = av.queryId
|
2025-02-20 19:02:44 +00:00
|
|
|
WHERE rq.queryId = $1
|
|
|
|
|
and isInVersion($2, rq.addedVersion, rq.removedVersion)
|
2025-02-11 15:22:59 +00:00
|
|
|
),
|
2025-02-14 10:56:24 +00:00
|
|
|
docs as (
|
2025-03-10 11:03:00 +00:00
|
|
|
SELECT id, clientId
|
2025-02-14 10:56:24 +00:00
|
|
|
FROM documents
|
2025-02-20 19:02:44 +00:00
|
|
|
WHERE id = $3
|
2025-02-14 10:56:24 +00:00
|
|
|
),
|
2025-02-11 15:22:59 +00:00
|
|
|
codeVersions as (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT
|
2025-02-11 15:22:59 +00:00
|
|
|
d.id as documentId,
|
2025-02-20 19:02:44 +00:00
|
|
|
mcv.minCleanVersion,
|
|
|
|
|
mtv.minTextVersion
|
2025-02-14 10:56:24 +00:00
|
|
|
FROM docs as d
|
2025-03-10 11:03:00 +00:00
|
|
|
JOIN currentCollectorMinTextVersions as mtv on mtv.clientId = d.clientId
|
|
|
|
|
JOIN currentCollectorMinCleanVersions as mcv on mcv.clientId = d.clientId
|
2025-02-11 15:22:59 +00:00
|
|
|
),
|
|
|
|
|
latestVersions AS (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT
|
|
|
|
|
r.id,
|
2025-02-11 15:22:59 +00:00
|
|
|
rq.queryId,
|
2025-05-05 09:31:21 +00:00
|
|
|
rq.queryType,
|
2025-02-11 15:22:59 +00:00
|
|
|
r.queryVersion,
|
2025-02-20 19:02:44 +00:00
|
|
|
r.textEntryId,
|
|
|
|
|
r.value,
|
2025-02-11 15:22:59 +00:00
|
|
|
ROW_NUMBER() OVER (
|
2025-02-20 19:02:44 +00:00
|
|
|
PARTITION BY r.queryId
|
|
|
|
|
ORDER BY r.id DESC
|
2025-02-11 15:22:59 +00:00
|
|
|
) as rowNumber
|
|
|
|
|
FROM reqQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN currentTextEntries as cte on cte.documentId = $3
|
2025-02-11 15:22:59 +00:00
|
|
|
LEFT JOIN results as r ON rq.queryId = r.queryId
|
|
|
|
|
and r.queryVersion = rq.activeVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
and cte.id = r.textEntryId
|
2025-02-11 15:22:59 +00:00
|
|
|
)
|
2025-05-05 09:31:21 +00:00
|
|
|
SELECT DISTINCT id, queryId, queryType, value
|
2025-02-20 19:02:44 +00:00
|
|
|
FROM latestVersions
|
|
|
|
|
WHERE rowNumber = 1
|
2025-01-29 11:52:37 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type ListQueryRequirementValuesParams struct {
|
2025-03-20 11:06:41 +00:00
|
|
|
Queryid *uuid.UUID `db:"queryid"`
|
|
|
|
|
Version *int32 `db:"version"`
|
|
|
|
|
Documentid *uuid.UUID `db:"documentid"`
|
2025-01-29 11:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListQueryRequirementValuesRow struct {
|
2025-05-05 09:31:21 +00:00
|
|
|
ID *uuid.UUID `db:"id"`
|
|
|
|
|
Queryid uuid.UUID `db:"queryid"`
|
|
|
|
|
Querytype Querytype `db:"querytype"`
|
|
|
|
|
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 (
|
2025-05-05 09:31:21 +00:00
|
|
|
// SELECT av.queryId, av.activeVersion, q.queryType
|
2025-01-29 11:52:37 +00:00
|
|
|
// FROM requiredQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
// JOIN queryCurrentActiveVersions as av on av.queryId = rq.requiredQueryId
|
2025-05-05 09:31:21 +00:00
|
|
|
// JOIN queries as q on q.queryId = av.queryId
|
2025-02-20 19:02:44 +00:00
|
|
|
// WHERE rq.queryId = $1
|
|
|
|
|
// and isInVersion($2, rq.addedVersion, rq.removedVersion)
|
2025-02-11 15:22:59 +00:00
|
|
|
// ),
|
2025-02-14 10:56:24 +00:00
|
|
|
// docs as (
|
2025-03-10 11:03:00 +00:00
|
|
|
// SELECT id, clientId
|
2025-02-14 10:56:24 +00:00
|
|
|
// FROM documents
|
2025-02-20 19:02:44 +00:00
|
|
|
// WHERE id = $3
|
2025-02-14 10:56:24 +00:00
|
|
|
// ),
|
2025-02-11 15:22:59 +00:00
|
|
|
// codeVersions as (
|
|
|
|
|
// SELECT
|
|
|
|
|
// d.id as documentId,
|
2025-02-20 19:02:44 +00:00
|
|
|
// mcv.minCleanVersion,
|
|
|
|
|
// mtv.minTextVersion
|
2025-02-14 10:56:24 +00:00
|
|
|
// FROM docs as d
|
2025-03-10 11:03:00 +00:00
|
|
|
// JOIN currentCollectorMinTextVersions as mtv on mtv.clientId = d.clientId
|
|
|
|
|
// JOIN currentCollectorMinCleanVersions as mcv on mcv.clientId = d.clientId
|
2025-02-11 15:22:59 +00:00
|
|
|
// ),
|
|
|
|
|
// latestVersions AS (
|
|
|
|
|
// SELECT
|
2025-02-20 19:02:44 +00:00
|
|
|
// r.id,
|
2025-02-11 15:22:59 +00:00
|
|
|
// rq.queryId,
|
2025-05-05 09:31:21 +00:00
|
|
|
// rq.queryType,
|
2025-02-11 15:22:59 +00:00
|
|
|
// r.queryVersion,
|
2025-02-20 19:02:44 +00:00
|
|
|
// r.textEntryId,
|
|
|
|
|
// r.value,
|
2025-02-11 15:22:59 +00:00
|
|
|
// ROW_NUMBER() OVER (
|
2025-02-20 19:02:44 +00:00
|
|
|
// PARTITION BY r.queryId
|
|
|
|
|
// ORDER BY r.id DESC
|
2025-02-11 15:22:59 +00:00
|
|
|
// ) as rowNumber
|
|
|
|
|
// FROM reqQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
// JOIN currentTextEntries as cte on cte.documentId = $3
|
2025-02-11 15:22:59 +00:00
|
|
|
// LEFT JOIN results as r ON rq.queryId = r.queryId
|
|
|
|
|
// and r.queryVersion = rq.activeVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
// and cte.id = r.textEntryId
|
2025-02-11 15:22:59 +00:00
|
|
|
// )
|
2025-05-05 09:31:21 +00:00
|
|
|
// SELECT DISTINCT id, queryId, queryType, value
|
2025-02-20 19:02:44 +00:00
|
|
|
// FROM latestVersions
|
|
|
|
|
// WHERE rowNumber = 1
|
2025-01-29 11:52:37 +00:00
|
|
|
func (q *Queries) ListQueryRequirementValues(ctx context.Context, arg *ListQueryRequirementValuesParams) ([]*ListQueryRequirementValuesRow, error) {
|
2025-02-20 19:02:44 +00:00
|
|
|
rows, err := q.db.Query(ctx, listQueryRequirementValues, arg.Queryid, arg.Version, arg.Documentid)
|
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-20 19:02:44 +00:00
|
|
|
if err := rows.Scan(
|
|
|
|
|
&i.ID,
|
|
|
|
|
&i.Queryid,
|
2025-05-05 09:31:21 +00:00
|
|
|
&i.Querytype,
|
2025-02-20 19:02:44 +00:00
|
|
|
&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 (
|
2025-03-10 11:03:00 +00:00
|
|
|
SELECT id, clientId from documents where id = $1
|
2025-02-11 15:22:59 +00:00
|
|
|
),
|
2025-05-06 01:59:52 +00:00
|
|
|
dependency_tree as (
|
|
|
|
|
select q.queryId, q.requiredIds, q.clientId, q.queryVersion
|
|
|
|
|
from docs,
|
|
|
|
|
LATERAL collectorQueryDependencyTreeByClient(docs.clientId) AS q
|
|
|
|
|
),
|
|
|
|
|
text_entries as (
|
|
|
|
|
select id, documentId from currentTextEntries where documentId = $1
|
|
|
|
|
),
|
2025-02-11 15:22:59 +00:00
|
|
|
unsyncedQueries AS (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT DISTINCT dt.queryId, dt.requiredIds
|
2025-02-11 15:22:59 +00:00
|
|
|
from docs as d
|
2025-05-06 01:59:52 +00:00
|
|
|
JOIN dependency_tree as dt on d.clientId = dt.clientId
|
|
|
|
|
JOIN text_entries as cte on cte.documentId = d.id
|
2025-02-20 19:02:44 +00:00
|
|
|
LEFT JOIN results as r
|
|
|
|
|
on r.queryId = dt.queryId
|
2025-01-29 11:52:37 +00:00
|
|
|
and r.queryVersion = dt.queryVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
and cte.id = r.textEntryId
|
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 (
|
2025-03-10 11:03:00 +00:00
|
|
|
// SELECT id, clientId from documents where id = $1
|
2025-02-11 15:22:59 +00:00
|
|
|
// ),
|
2025-05-06 01:59:52 +00:00
|
|
|
// dependency_tree as (
|
|
|
|
|
// select q.queryId, q.requiredIds, q.clientId, q.queryVersion
|
|
|
|
|
// from docs,
|
|
|
|
|
// LATERAL collectorQueryDependencyTreeByClient(docs.clientId) AS q
|
|
|
|
|
// ),
|
|
|
|
|
// text_entries as (
|
|
|
|
|
// select id, documentId from currentTextEntries where documentId = $1
|
|
|
|
|
// ),
|
2025-02-11 15:22:59 +00:00
|
|
|
// unsyncedQueries AS (
|
2025-02-20 19:02:44 +00:00
|
|
|
// SELECT DISTINCT dt.queryId, dt.requiredIds
|
2025-02-11 15:22:59 +00:00
|
|
|
// from docs as d
|
2025-05-06 01:59:52 +00:00
|
|
|
// JOIN dependency_tree as dt on d.clientId = dt.clientId
|
|
|
|
|
// JOIN text_entries as cte on cte.documentId = d.id
|
2025-02-20 19:02:44 +00:00
|
|
|
// LEFT JOIN results as r
|
|
|
|
|
// on r.queryId = dt.queryId
|
2025-01-29 11:52:37 +00:00
|
|
|
// and r.queryVersion = dt.queryVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
// and cte.id = r.textEntryId
|
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-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) ListUnsyncedNoDepsQueriesByDocId(ctx context.Context, dollar_1 *uuid.UUID) ([]*uuid.UUID, error) {
|
2025-02-11 15:22:59 +00:00
|
|
|
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-03-20 11:06:41 +00:00
|
|
|
items := []*uuid.UUID{}
|
2024-12-19 18:49:22 +00:00
|
|
|
for rows.Next() {
|
2025-03-20 11:06:41 +00:00
|
|
|
var queryid *uuid.UUID
|
2025-02-11 15:22:59 +00:00
|
|
|
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
|
|
|
|
|
}
|