Merged in feature/part (pull request #113)
Size Import Parts * parts * think * workingpart * textout
This commit is contained in:
@@ -9,30 +9,47 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addDocumentText = `-- name: AddDocumentText :one
|
||||
INSERT INTO documentTextExtractions (bucket, key, hash) VALUES ($1, $2, $3) returning id
|
||||
INSERT INTO documentTextExtractions
|
||||
(bucket, key, hash, createdAt, part)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
returning id
|
||||
`
|
||||
|
||||
type AddDocumentTextParams struct {
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Hash string `db:"hash"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Hash string `db:"hash"`
|
||||
Createdat pgtype.Timestamp `db:"createdat"`
|
||||
Part uint16 `db:"part"`
|
||||
}
|
||||
|
||||
// AddDocumentText
|
||||
//
|
||||
// INSERT INTO documentTextExtractions (bucket, key, hash) VALUES ($1, $2, $3) returning id
|
||||
// INSERT INTO documentTextExtractions
|
||||
// (bucket, key, hash, createdAt, part)
|
||||
// VALUES ($1, $2, $3, $4, $5)
|
||||
// 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.Hash)
|
||||
row := q.db.QueryRow(ctx, addDocumentText,
|
||||
arg.Bucket,
|
||||
arg.Key,
|
||||
arg.Hash,
|
||||
arg.Createdat,
|
||||
arg.Part,
|
||||
)
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :exec
|
||||
INSERT INTO documentTextExtractionEntries (textId, triggerId, version) VALUES ($1, $2, $3)
|
||||
INSERT INTO documentTextExtractionEntries
|
||||
(textId, triggerId, version)
|
||||
VALUES ($1, $2, $3)
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
@@ -43,33 +60,50 @@ type AddDocumentTextEntryParams struct {
|
||||
|
||||
// AddDocumentTextEntry
|
||||
//
|
||||
// INSERT INTO documentTextExtractionEntries (textId, triggerId, version) VALUES ($1, $2, $3)
|
||||
// INSERT INTO documentTextExtractionEntries
|
||||
// (textId, triggerId, version)
|
||||
// VALUES ($1, $2, $3)
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) error {
|
||||
_, err := q.db.Exec(ctx, addDocumentTextEntry, arg.Textid, arg.Triggerid, arg.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
const addDocumentTextTrigger = `-- name: AddDocumentTextTrigger :one
|
||||
INSERT INTO documentTextTriggerExtractions (cleanId, version) VALUES ($1, $2) returning id
|
||||
INSERT INTO documentTextTriggerExtractions
|
||||
(cleanId, version, createdAt, part) VALUES
|
||||
($1, $2, $3, $4)
|
||||
returning id
|
||||
`
|
||||
|
||||
type AddDocumentTextTriggerParams struct {
|
||||
Cleanid uuid.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
Cleanid uuid.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
Createdat pgtype.Timestamp `db:"createdat"`
|
||||
Part uint16 `db:"part"`
|
||||
}
|
||||
|
||||
// AddDocumentTextTrigger
|
||||
//
|
||||
// INSERT INTO documentTextTriggerExtractions (cleanId, version) VALUES ($1, $2) returning id
|
||||
// INSERT INTO documentTextTriggerExtractions
|
||||
// (cleanId, version, createdAt, part) VALUES
|
||||
// ($1, $2, $3, $4)
|
||||
// returning id
|
||||
func (q *Queries) AddDocumentTextTrigger(ctx context.Context, arg *AddDocumentTextTriggerParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentTextTrigger, arg.Cleanid, arg.Version)
|
||||
row := q.db.QueryRow(ctx, addDocumentTextTrigger,
|
||||
arg.Cleanid,
|
||||
arg.Version,
|
||||
arg.Createdat,
|
||||
arg.Part,
|
||||
)
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const addDocumentTextTriggerJobId = `-- name: AddDocumentTextTriggerJobId :exec
|
||||
UPDATE documentTextTriggerExtractions SET textractJobId = $1 WHERE id = $2
|
||||
UPDATE documentTextTriggerExtractions
|
||||
SET textractJobId = $1
|
||||
WHERE id = $2
|
||||
`
|
||||
|
||||
type AddDocumentTextTriggerJobIdParams struct {
|
||||
@@ -79,7 +113,9 @@ type AddDocumentTextTriggerJobIdParams struct {
|
||||
|
||||
// AddDocumentTextTriggerJobId
|
||||
//
|
||||
// UPDATE documentTextTriggerExtractions SET textractJobId = $1 WHERE id = $2
|
||||
// UPDATE documentTextTriggerExtractions
|
||||
// SET textractJobId = $1
|
||||
// WHERE id = $2
|
||||
func (q *Queries) AddDocumentTextTriggerJobId(ctx context.Context, arg *AddDocumentTextTriggerJobIdParams) error {
|
||||
_, err := q.db.Exec(ctx, addDocumentTextTriggerJobId, arg.Textractjobid, arg.ID)
|
||||
return err
|
||||
@@ -169,6 +205,142 @@ func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid uuid.UUID)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getTextOutCurrentPart = `-- name: GetTextOutCurrentPart :one
|
||||
WITH client as (
|
||||
select id from clients where id = $1
|
||||
),
|
||||
parts as (
|
||||
SELECT extractions.part
|
||||
FROM client as c
|
||||
JOIN documents as docs on docs.clientId = c.id
|
||||
JOIN documentCleans as clean on docs.id = clean.documentId
|
||||
JOIN documentTextTriggerExtractions as triggers
|
||||
on triggers.cleanId = clean.id
|
||||
JOIN documentTextExtractionEntries as textEntries
|
||||
on textEntries.triggerId = triggers.id
|
||||
JOIN documentTextExtractions as extractions
|
||||
on extractions.id = textEntries.textId
|
||||
WHERE date(extractions.createdAt) = date($2)
|
||||
),
|
||||
max_part as (
|
||||
SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
||||
)
|
||||
SELECT
|
||||
COALESCE(p.part, 0)::unsignedsmallint as part,
|
||||
COUNT(p.part) as count
|
||||
FROM parts p
|
||||
RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
||||
GROUP BY p.part
|
||||
`
|
||||
|
||||
type GetTextOutCurrentPartParams struct {
|
||||
Clientid *string `db:"clientid"`
|
||||
Querydate pgtype.Timestamptz `db:"querydate"`
|
||||
}
|
||||
|
||||
type GetTextOutCurrentPartRow struct {
|
||||
Part uint16 `db:"part"`
|
||||
Count int64 `db:"count"`
|
||||
}
|
||||
|
||||
// GetTextOutCurrentPart
|
||||
//
|
||||
// WITH client as (
|
||||
// select id from clients where id = $1
|
||||
// ),
|
||||
// parts as (
|
||||
// SELECT extractions.part
|
||||
// FROM client as c
|
||||
// JOIN documents as docs on docs.clientId = c.id
|
||||
// JOIN documentCleans as clean on docs.id = clean.documentId
|
||||
// JOIN documentTextTriggerExtractions as triggers
|
||||
// on triggers.cleanId = clean.id
|
||||
// JOIN documentTextExtractionEntries as textEntries
|
||||
// on textEntries.triggerId = triggers.id
|
||||
// JOIN documentTextExtractions as extractions
|
||||
// on extractions.id = textEntries.textId
|
||||
// WHERE date(extractions.createdAt) = date($2)
|
||||
// ),
|
||||
// max_part as (
|
||||
// SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
||||
// )
|
||||
// SELECT
|
||||
// COALESCE(p.part, 0)::unsignedsmallint as part,
|
||||
// COUNT(p.part) as count
|
||||
// FROM parts p
|
||||
// RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
||||
// GROUP BY p.part
|
||||
func (q *Queries) GetTextOutCurrentPart(ctx context.Context, arg *GetTextOutCurrentPartParams) (*GetTextOutCurrentPartRow, error) {
|
||||
row := q.db.QueryRow(ctx, getTextOutCurrentPart, arg.Clientid, arg.Querydate)
|
||||
var i GetTextOutCurrentPartRow
|
||||
err := row.Scan(&i.Part, &i.Count)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getTextractOutputCurrentPart = `-- name: GetTextractOutputCurrentPart :one
|
||||
WITH client as (
|
||||
select id from clients where id = $1
|
||||
),
|
||||
parts as (
|
||||
SELECT triggers.part
|
||||
FROM client as c
|
||||
JOIN documents as docs on docs.clientId = c.id
|
||||
JOIN documentCleans as clean on docs.id = clean.documentId
|
||||
JOIN documentTextTriggerExtractions as triggers
|
||||
on triggers.cleanId = clean.id
|
||||
WHERE date(triggers.createdAt) = date($2)
|
||||
),
|
||||
max_part as (
|
||||
SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
||||
)
|
||||
SELECT
|
||||
COALESCE(p.part, 0)::unsignedsmallint as part,
|
||||
COUNT(p.part) as count
|
||||
FROM parts p
|
||||
RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
||||
GROUP BY p.part
|
||||
`
|
||||
|
||||
type GetTextractOutputCurrentPartParams struct {
|
||||
Clientid *string `db:"clientid"`
|
||||
Querydate pgtype.Timestamptz `db:"querydate"`
|
||||
}
|
||||
|
||||
type GetTextractOutputCurrentPartRow struct {
|
||||
Part uint16 `db:"part"`
|
||||
Count int64 `db:"count"`
|
||||
}
|
||||
|
||||
// GetTextractOutputCurrentPart
|
||||
//
|
||||
// WITH client as (
|
||||
// select id from clients where id = $1
|
||||
// ),
|
||||
// parts as (
|
||||
// SELECT triggers.part
|
||||
// FROM client as c
|
||||
// JOIN documents as docs on docs.clientId = c.id
|
||||
// JOIN documentCleans as clean on docs.id = clean.documentId
|
||||
// JOIN documentTextTriggerExtractions as triggers
|
||||
// on triggers.cleanId = clean.id
|
||||
// WHERE date(triggers.createdAt) = date($2)
|
||||
// ),
|
||||
// max_part as (
|
||||
// SELECT COALESCE(max(part), 0) as max_part_num FROM parts
|
||||
// )
|
||||
// SELECT
|
||||
// COALESCE(p.part, 0)::unsignedsmallint as part,
|
||||
// COUNT(p.part) as count
|
||||
// FROM parts p
|
||||
// RIGHT JOIN max_part mp ON p.part = mp.max_part_num
|
||||
// GROUP BY p.part
|
||||
func (q *Queries) GetTextractOutputCurrentPart(ctx context.Context, arg *GetTextractOutputCurrentPartParams) (*GetTextractOutputCurrentPartRow, error) {
|
||||
row := q.db.QueryRow(ctx, getTextractOutputCurrentPart, arg.Clientid, arg.Querydate)
|
||||
var i GetTextractOutputCurrentPartRow
|
||||
err := row.Scan(&i.Part, &i.Count)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const isDocumentTextExtracted = `-- name: IsDocumentTextExtracted :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
||||
|
||||
Reference in New Issue
Block a user