Merged in feature/textextract (pull request #108)
Start adding Textract + UUID changes * base * startclient * ts * short * tests
This commit is contained in:
@@ -8,47 +8,95 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :one
|
||||
INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4) returning id
|
||||
const addDocumentText = `-- name: AddDocumentText :one
|
||||
INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
Version int64 `db:"version"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Cleanentryid pgtype.UUID `db:"cleanentryid"`
|
||||
type AddDocumentTextParams struct {
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// AddDocumentTextEntry
|
||||
// AddDocumentText
|
||||
//
|
||||
// INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4) returning id
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentTextEntry,
|
||||
arg.Version,
|
||||
// INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id
|
||||
func (q *Queries) AddDocumentText(ctx context.Context, arg *AddDocumentTextParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentText,
|
||||
arg.Bucket,
|
||||
arg.Key,
|
||||
arg.Cleanentryid,
|
||||
arg.Hash,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :exec
|
||||
INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
Textid uuid.UUID `db:"textid"`
|
||||
Version int64 `db:"version"`
|
||||
}
|
||||
|
||||
// AddDocumentTextEntry
|
||||
//
|
||||
// INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2)
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) error {
|
||||
_, err := q.db.Exec(ctx, addDocumentTextEntry, arg.Textid, arg.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
const getDocumentTextExtractionByHash = `-- name: GetDocumentTextExtractionByHash :one
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE cleanEntryId = $1 and hash = $2
|
||||
`
|
||||
|
||||
type GetDocumentTextExtractionByHashParams struct {
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// GetDocumentTextExtractionByHash
|
||||
//
|
||||
// SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
// FROM currentTextEntries
|
||||
// WHERE cleanEntryId = $1 and hash = $2
|
||||
func (q *Queries) GetDocumentTextExtractionByHash(ctx context.Context, arg *GetDocumentTextExtractionByHashParams) (*Currenttextentry, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentTextExtractionByHash, arg.Cleanentryid, arg.Hash)
|
||||
var i Currenttextentry
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Documentid,
|
||||
&i.Bucket,
|
||||
&i.Key,
|
||||
&i.Version,
|
||||
&i.Hash,
|
||||
&i.Cleanentryid,
|
||||
)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getTextEntryByDocId = `-- name: GetTextEntryByDocId :one
|
||||
SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE documentId = $1
|
||||
`
|
||||
|
||||
// GetTextEntryByDocId
|
||||
//
|
||||
// SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
// SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
// FROM currentTextEntries
|
||||
// WHERE documentId = $1
|
||||
func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid pgtype.UUID) (*Currenttextentry, error) {
|
||||
func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid uuid.UUID) (*Currenttextentry, error) {
|
||||
row := q.db.QueryRow(ctx, getTextEntryByDocId, documentid)
|
||||
var i Currenttextentry
|
||||
err := row.Scan(
|
||||
@@ -57,6 +105,7 @@ func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid pgtype.UUI
|
||||
&i.Bucket,
|
||||
&i.Key,
|
||||
&i.Version,
|
||||
&i.Hash,
|
||||
&i.Cleanentryid,
|
||||
)
|
||||
return &i, err
|
||||
@@ -73,7 +122,7 @@ SELECT EXISTS(
|
||||
// SELECT EXISTS(
|
||||
// SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid pgtype.UUID) (bool, error) {
|
||||
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, isDocumentTextExtracted, documentid)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
|
||||
Reference in New Issue
Block a user