// 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 reqQueries as ( SELECT q.id as queryId, q.activeVersion, q.type FROM requiredQueries as rq JOIN queries as q on q.id = rq.requiredQueryId 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 ` type ListQueryRequirementValuesParams struct { Documentid pgtype.UUID `db:"documentid"` Queryid pgtype.UUID `db:"queryid"` Version int32 `db:"version"` } type ListQueryRequirementValuesRow struct { Queryid pgtype.UUID `db:"queryid"` Type Querytype `db:"type"` Value string `db:"value"` } // ListQueryRequirementValues // // WITH reqQueries as ( // SELECT q.id as queryId, q.activeVersion, q.type // FROM requiredQueries as rq // JOIN queries as q on q.id = rq.requiredQueryId // 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 func (q *Queries) ListQueryRequirementValues(ctx context.Context, arg *ListQueryRequirementValuesParams) ([]*ListQueryRequirementValuesRow, error) { rows, err := q.db.Query(ctx, listQueryRequirementValues, arg.Documentid, arg.Queryid, arg.Version) if err != nil { return nil, err } defer rows.Close() items := []*ListQueryRequirementValuesRow{} for rows.Next() { var i ListQueryRequirementValuesRow if err := rows.Scan(&i.Queryid, &i.Type, &i.Value); err != nil { return nil, err } items = append(items, &i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } 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 LEFT JOIN results as r on r.queryId = dt.queryId and r.documentId = d.id and r.queryVersion = dt.queryVersion and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion where r.value is null ) SELECT DISTINCT queryId FROM unsyncedQueries as baseuq WHERE NOT EXISTS ( SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds) ) ` // ListUnsyncedNoDepsQueriesByDocId // // 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 // LEFT JOIN results as r on r.queryId = dt.queryId // and r.documentId = d.id // and r.queryVersion = dt.queryVersion // and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion // where r.value is null // ) // 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) if err != nil { return nil, err } defer rows.Close() items := []pgtype.UUID{} for rows.Next() { var queryid pgtype.UUID if err := rows.Scan(&queryid); err != nil { return nil, err } items = append(items, queryid) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const setResult = `-- name: SetResult :exec INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6) ` 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) func (q *Queries) SetResult(ctx context.Context, arg *SetResultParams) error { _, err := q.db.Exec(ctx, setResult, arg.Queryid, arg.Documentid, arg.Value, arg.Cleanversion, arg.Textversion, arg.Queryversion, ) return err }