queuecreation
This commit is contained in:
@@ -110,7 +110,7 @@ type Result struct {
|
||||
ID pgtype.UUID
|
||||
Queryid pgtype.UUID
|
||||
Documentid pgtype.UUID
|
||||
Value pgtype.Text
|
||||
Value string
|
||||
Cleanversion int32
|
||||
Textversion int32
|
||||
Queryversion int32
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
@@ -14,3 +16,16 @@ func ToDBUUID(id uuid.UUID) (pgtype.UUID, error) {
|
||||
|
||||
return dbID, nil
|
||||
}
|
||||
|
||||
func MustToDBUUID(id uuid.UUID) pgtype.UUID {
|
||||
dbID, err := ToDBUUID(id)
|
||||
if err != nil {
|
||||
panic(fmt.Sprint("id is not valid: ", id))
|
||||
}
|
||||
|
||||
return dbID
|
||||
}
|
||||
|
||||
func MustToUUID(id pgtype.UUID) uuid.UUID {
|
||||
return uuid.Must(uuid.FromBytes(id.Bytes[:]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user