queuecreation

This commit is contained in:
Michael McGuinness
2024-12-20 17:35:33 +00:00
parent 6b07844d46
commit f95114e11a
11 changed files with 603 additions and 89 deletions
+59 -10
View File
@@ -11,8 +11,38 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
const listResultValuesByID = `-- name: ListResultValuesByID :many
SELECT id, queryId, value FROM results where id = ANY($1)
`
type ListResultValuesByIDRow struct {
ID pgtype.UUID
Queryid pgtype.UUID
Value string
}
func (q *Queries) ListResultValuesByID(ctx context.Context, id []pgtype.UUID) ([]ListResultValuesByIDRow, error) {
rows, err := q.db.Query(ctx, listResultValuesByID, id)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListResultValuesByIDRow
for rows.Next() {
var i ListResultValuesByIDRow
if err := rows.Scan(&i.ID, &i.Queryid, &i.Value); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listResultsByDocumentID = `-- name: ListResultsByDocumentID :many
SELECT id, queryId, cleanVersion, textVersion, queryVersion FROM results where documentId = $1 and cleanVersion >= $2 and textVersion >= $3
SELECT id, queryId, queryVersion FROM results where documentId = $1 and cleanVersion >= $2 and textVersion >= $3
`
type ListResultsByDocumentIDParams struct {
@@ -24,8 +54,6 @@ type ListResultsByDocumentIDParams struct {
type ListResultsByDocumentIDRow struct {
ID pgtype.UUID
Queryid pgtype.UUID
Cleanversion int32
Textversion int32
Queryversion int32
}
@@ -38,13 +66,7 @@ func (q *Queries) ListResultsByDocumentID(ctx context.Context, arg ListResultsBy
var items []ListResultsByDocumentIDRow
for rows.Next() {
var i ListResultsByDocumentIDRow
if err := rows.Scan(
&i.ID,
&i.Queryid,
&i.Cleanversion,
&i.Textversion,
&i.Queryversion,
); err != nil {
if err := rows.Scan(&i.ID, &i.Queryid, &i.Queryversion); err != nil {
return nil, err
}
items = append(items, i)
@@ -54,3 +76,30 @@ func (q *Queries) ListResultsByDocumentID(ctx context.Context, arg ListResultsBy
}
return items, nil
}
const setResult = `-- name: SetResult :exec
INSERT INTO results (id, queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6, $7)
`
type SetResultParams struct {
ID pgtype.UUID
Queryid pgtype.UUID
Documentid pgtype.UUID
Value string
Cleanversion int32
Textversion int32
Queryversion int32
}
func (q *Queries) SetResult(ctx context.Context, arg SetResultParams) error {
_, err := q.db.Exec(ctx, setResult,
arg.ID,
arg.Queryid,
arg.Documentid,
arg.Value,
arg.Cleanversion,
arg.Textversion,
arg.Queryversion,
)
return err
}