Merged in feature/jobsynced (pull request #72)
Job Status Get and DB tidy up * initalquery * tests * shorttests * testing queries * job * solvedthequery * updatingdb * fixingtests * repotests * shorttests * docker * testspassed
This commit is contained in:
@@ -12,95 +12,64 @@ import (
|
||||
)
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :exec
|
||||
INSERT INTO documentTextExtractions (documentId, version, bucket, key) VALUES ($1, $2, $3, $4)
|
||||
INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4)
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Version int32 `db:"version"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Version int32 `db:"version"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Cleanentryid pgtype.UUID `db:"cleanentryid"`
|
||||
}
|
||||
|
||||
// AddDocumentTextEntry
|
||||
//
|
||||
// INSERT INTO documentTextExtractions (documentId, version, bucket, key) VALUES ($1, $2, $3, $4)
|
||||
// INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4)
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) error {
|
||||
_, err := q.db.Exec(ctx, addDocumentTextEntry,
|
||||
arg.Documentid,
|
||||
arg.Version,
|
||||
arg.Bucket,
|
||||
arg.Key,
|
||||
arg.Cleanentryid,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const getDocumentTextEntry = `-- name: GetDocumentTextEntry :one
|
||||
SELECT dc.documentId, dc.bucket, dc.key, dc.version
|
||||
FROM documentTextExtractions AS dc
|
||||
JOIN documents AS d ON d.id = dc.documentId
|
||||
LEFT JOIN collectors as c ON d.jobId = c.jobId
|
||||
LEFT JOIN collectorCurrentActiveVersions as av on c.id = av.collectorId
|
||||
LEFT JOIN collectorMinTextVersions AS ccv ON c.id = ccv.collectorId
|
||||
and isInVersion(av.id, ccv.addedVersion, ccv.removedVersion)
|
||||
WHERE dc.documentId = $1 and dc.version >= coalesce(ccv.versionId, 1)
|
||||
ORDER BY d.id DESC LIMIT 1
|
||||
SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE documentId = $1
|
||||
`
|
||||
|
||||
type GetDocumentTextEntryRow struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Version int32 `db:"version"`
|
||||
}
|
||||
|
||||
// GetDocumentTextEntry
|
||||
//
|
||||
// SELECT dc.documentId, dc.bucket, dc.key, dc.version
|
||||
// FROM documentTextExtractions AS dc
|
||||
// JOIN documents AS d ON d.id = dc.documentId
|
||||
// LEFT JOIN collectors as c ON d.jobId = c.jobId
|
||||
// LEFT JOIN collectorCurrentActiveVersions as av on c.id = av.collectorId
|
||||
// LEFT JOIN collectorMinTextVersions AS ccv ON c.id = ccv.collectorId
|
||||
// and isInVersion(av.id, ccv.addedVersion, ccv.removedVersion)
|
||||
// WHERE dc.documentId = $1 and dc.version >= coalesce(ccv.versionId, 1)
|
||||
// ORDER BY d.id DESC LIMIT 1
|
||||
func (q *Queries) GetDocumentTextEntry(ctx context.Context, documentid pgtype.UUID) (*GetDocumentTextEntryRow, error) {
|
||||
// SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
// FROM currentTextEntries
|
||||
// WHERE documentId = $1
|
||||
func (q *Queries) GetDocumentTextEntry(ctx context.Context, documentid pgtype.UUID) (*Currenttextentry, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentTextEntry, documentid)
|
||||
var i GetDocumentTextEntryRow
|
||||
var i Currenttextentry
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Documentid,
|
||||
&i.Bucket,
|
||||
&i.Key,
|
||||
&i.Version,
|
||||
&i.Cleanentryid,
|
||||
)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const isDocumentTextExtracted = `-- name: IsDocumentTextExtracted :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1
|
||||
FROM documentTextExtractions AS dc
|
||||
JOIN documents AS d ON d.id = dc.documentId
|
||||
LEFT JOIN collectors as c ON d.jobId = c.jobId
|
||||
LEFT JOIN collectorCurrentActiveVersions as av on c.id = av.collectorId
|
||||
LEFT JOIN collectorMinTextVersions AS ccv ON c.id = ccv.collectorId
|
||||
and isInVersion(av.id, ccv.addedVersion, ccv.removedVersion)
|
||||
WHERE dc.documentId = $1 and dc.version >= coalesce(ccv.versionId, 1)
|
||||
SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
||||
)
|
||||
`
|
||||
|
||||
// IsDocumentTextExtracted
|
||||
//
|
||||
// SELECT EXISTS(
|
||||
// SELECT 1
|
||||
// FROM documentTextExtractions AS dc
|
||||
// JOIN documents AS d ON d.id = dc.documentId
|
||||
// LEFT JOIN collectors as c ON d.jobId = c.jobId
|
||||
// LEFT JOIN collectorCurrentActiveVersions as av on c.id = av.collectorId
|
||||
// LEFT JOIN collectorMinTextVersions AS ccv ON c.id = ccv.collectorId
|
||||
// and isInVersion(av.id, ccv.addedVersion, ccv.removedVersion)
|
||||
// WHERE dc.documentId = $1 and dc.version >= coalesce(ccv.versionId, 1)
|
||||
// SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid pgtype.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, isDocumentTextExtracted, documentid)
|
||||
|
||||
Reference in New Issue
Block a user