@@ -1,5 +1,5 @@
|
||||
CREATE TABLE queries (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
latestVersion int not null default 1,
|
||||
activeVersion int not null default 1,
|
||||
type queryType not null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE collectors (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
jobId uuid not null,
|
||||
minCleanVersion int not null default 1,
|
||||
minTextVersion int not null default 1,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE collectorQueries (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
collectorId uuid not null,
|
||||
name varchar(255) not null,
|
||||
queryId uuid not null,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE results (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
queryId uuid not null,
|
||||
documentId uuid not null,
|
||||
value TEXT not null,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE requiredQueries (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
queryId uuid not null,
|
||||
requiredQueryId uuid not null,
|
||||
addedVersion int not null,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE queryConfigs (
|
||||
id uuid primary key,
|
||||
id uuid primary key DEFAULT gen_random_uuid(),
|
||||
queryId uuid not null,
|
||||
config jsonb not null,
|
||||
addedVersion int not null,
|
||||
|
||||
@@ -4,5 +4,5 @@ SELECT id, queryId, queryVersion FROM results where documentId = $1 and cleanVer
|
||||
-- name: ListResultValuesByID :many
|
||||
SELECT id, queryId, value FROM results where id = ANY($1);
|
||||
|
||||
-- name: SetResult :exec
|
||||
INSERT INTO results (id, queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6, $7);
|
||||
-- name: SetResult :one
|
||||
INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id;
|
||||
@@ -77,12 +77,11 @@ 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)
|
||||
const setResult = `-- name: SetResult :one
|
||||
INSERT INTO results (queryId, documentId, value, cleanVersion, textVersion, queryVersion) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id
|
||||
`
|
||||
|
||||
type SetResultParams struct {
|
||||
ID pgtype.UUID
|
||||
Queryid pgtype.UUID
|
||||
Documentid pgtype.UUID
|
||||
Value string
|
||||
@@ -91,9 +90,8 @@ type SetResultParams struct {
|
||||
Queryversion int32
|
||||
}
|
||||
|
||||
func (q *Queries) SetResult(ctx context.Context, arg SetResultParams) error {
|
||||
_, err := q.db.Exec(ctx, setResult,
|
||||
arg.ID,
|
||||
func (q *Queries) SetResult(ctx context.Context, arg SetResultParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, setResult,
|
||||
arg.Queryid,
|
||||
arg.Documentid,
|
||||
arg.Value,
|
||||
@@ -101,5 +99,7 @@ func (q *Queries) SetResult(ctx context.Context, arg SetResultParams) error {
|
||||
arg.Textversion,
|
||||
arg.Queryversion,
|
||||
)
|
||||
return err
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
@@ -28,10 +28,7 @@ type ResultStore struct {
|
||||
}
|
||||
|
||||
func Store(ctx context.Context, db *repository.Queries, res *ResultStore) (uuid.UUID, error) {
|
||||
id := uuid.New()
|
||||
|
||||
err := db.SetResult(ctx, repository.SetResultParams{
|
||||
ID: database.MustToDBUUID(id),
|
||||
dbId, err := db.SetResult(ctx, repository.SetResultParams{
|
||||
Queryid: database.MustToDBUUID(res.QueryID),
|
||||
Documentid: database.MustToDBUUID(res.DocumentID),
|
||||
Value: res.Value,
|
||||
@@ -43,5 +40,7 @@ func Store(ctx context.Context, db *repository.Queries, res *ResultStore) (uuid.
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
id := database.MustToUUID(dbId)
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user