2025-02-07 14:15:06 +00:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
|
// versions:
|
|
|
|
|
// sqlc v1.27.0
|
|
|
|
|
// source: text.sql
|
|
|
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
"github.com/google/uuid"
|
2025-04-08 12:44:09 +00:00
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
2025-02-07 14:15:06 +00:00
|
|
|
)
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
const addDocumentText = `-- name: AddDocumentText :one
|
2025-04-08 12:44:09 +00:00
|
|
|
INSERT INTO documentTextExtractions
|
|
|
|
|
(bucket, key, hash, createdAt, part)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
|
|
|
returning id
|
2025-02-07 14:15:06 +00:00
|
|
|
`
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
type AddDocumentTextParams struct {
|
2025-04-08 12:44:09 +00:00
|
|
|
Bucket string `db:"bucket"`
|
|
|
|
|
Key string `db:"key"`
|
|
|
|
|
Hash string `db:"hash"`
|
|
|
|
|
Createdat pgtype.Timestamp `db:"createdat"`
|
|
|
|
|
Part uint16 `db:"part"`
|
2025-02-07 14:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
// AddDocumentText
|
2025-02-07 14:15:06 +00:00
|
|
|
//
|
2025-04-08 12:44:09 +00:00
|
|
|
// INSERT INTO documentTextExtractions
|
|
|
|
|
// (bucket, key, hash, createdAt, part)
|
|
|
|
|
// VALUES ($1, $2, $3, $4, $5)
|
|
|
|
|
// returning id
|
2025-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) AddDocumentText(ctx context.Context, arg *AddDocumentTextParams) (uuid.UUID, error) {
|
2025-04-08 12:44:09 +00:00
|
|
|
row := q.db.QueryRow(ctx, addDocumentText,
|
|
|
|
|
arg.Bucket,
|
|
|
|
|
arg.Key,
|
|
|
|
|
arg.Hash,
|
|
|
|
|
arg.Createdat,
|
|
|
|
|
arg.Part,
|
|
|
|
|
)
|
2025-03-20 11:06:41 +00:00
|
|
|
var id uuid.UUID
|
2025-03-17 18:14:15 +00:00
|
|
|
err := row.Scan(&id)
|
|
|
|
|
return id, err
|
2025-02-07 14:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :exec
|
2025-04-08 12:44:09 +00:00
|
|
|
INSERT INTO documentTextExtractionEntries
|
|
|
|
|
(textId, triggerId, version)
|
|
|
|
|
VALUES ($1, $2, $3)
|
2025-03-20 11:06:41 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type AddDocumentTextEntryParams struct {
|
2025-04-02 18:50:03 +00:00
|
|
|
Textid uuid.UUID `db:"textid"`
|
|
|
|
|
Triggerid uuid.UUID `db:"triggerid"`
|
|
|
|
|
Version int64 `db:"version"`
|
2025-03-20 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddDocumentTextEntry
|
|
|
|
|
//
|
2025-04-08 12:44:09 +00:00
|
|
|
// INSERT INTO documentTextExtractionEntries
|
|
|
|
|
// (textId, triggerId, version)
|
|
|
|
|
// VALUES ($1, $2, $3)
|
2025-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) error {
|
2025-04-02 18:50:03 +00:00
|
|
|
_, err := q.db.Exec(ctx, addDocumentTextEntry, arg.Textid, arg.Triggerid, arg.Version)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addDocumentTextTrigger = `-- name: AddDocumentTextTrigger :one
|
2025-04-08 12:44:09 +00:00
|
|
|
INSERT INTO documentTextTriggerExtractions
|
|
|
|
|
(cleanId, version, createdAt, part) VALUES
|
|
|
|
|
($1, $2, $3, $4)
|
|
|
|
|
returning id
|
2025-04-02 18:50:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type AddDocumentTextTriggerParams struct {
|
2025-04-08 12:44:09 +00:00
|
|
|
Cleanid uuid.UUID `db:"cleanid"`
|
|
|
|
|
Version int64 `db:"version"`
|
|
|
|
|
Createdat pgtype.Timestamp `db:"createdat"`
|
|
|
|
|
Part uint16 `db:"part"`
|
2025-04-02 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddDocumentTextTrigger
|
|
|
|
|
//
|
2025-04-08 12:44:09 +00:00
|
|
|
// INSERT INTO documentTextTriggerExtractions
|
|
|
|
|
// (cleanId, version, createdAt, part) VALUES
|
|
|
|
|
// ($1, $2, $3, $4)
|
|
|
|
|
// returning id
|
2025-04-02 18:50:03 +00:00
|
|
|
func (q *Queries) AddDocumentTextTrigger(ctx context.Context, arg *AddDocumentTextTriggerParams) (uuid.UUID, error) {
|
2025-04-08 12:44:09 +00:00
|
|
|
row := q.db.QueryRow(ctx, addDocumentTextTrigger,
|
|
|
|
|
arg.Cleanid,
|
|
|
|
|
arg.Version,
|
|
|
|
|
arg.Createdat,
|
|
|
|
|
arg.Part,
|
|
|
|
|
)
|
2025-04-02 18:50:03 +00:00
|
|
|
var id uuid.UUID
|
|
|
|
|
err := row.Scan(&id)
|
|
|
|
|
return id, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addDocumentTextTriggerJobId = `-- name: AddDocumentTextTriggerJobId :exec
|
2025-04-08 12:44:09 +00:00
|
|
|
UPDATE documentTextTriggerExtractions
|
|
|
|
|
SET textractJobId = $1
|
|
|
|
|
WHERE id = $2
|
2025-04-02 18:50:03 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type AddDocumentTextTriggerJobIdParams struct {
|
|
|
|
|
Textractjobid *string `db:"textractjobid"`
|
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddDocumentTextTriggerJobId
|
|
|
|
|
//
|
2025-04-08 12:44:09 +00:00
|
|
|
// UPDATE documentTextTriggerExtractions
|
|
|
|
|
// SET textractJobId = $1
|
|
|
|
|
// WHERE id = $2
|
2025-04-02 18:50:03 +00:00
|
|
|
func (q *Queries) AddDocumentTextTriggerJobId(ctx context.Context, arg *AddDocumentTextTriggerJobIdParams) error {
|
|
|
|
|
_, err := q.db.Exec(ctx, addDocumentTextTriggerJobId, arg.Textractjobid, arg.ID)
|
2025-03-20 11:06:41 +00:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getDocumentTextExtractionByHash = `-- name: GetDocumentTextExtractionByHash :one
|
2025-04-02 18:50:03 +00:00
|
|
|
SELECT id FROM currentTextEntries WHERE cleanId = $1 and hash = $2
|
2025-03-20 11:06:41 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type GetDocumentTextExtractionByHashParams struct {
|
|
|
|
|
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
|
|
|
|
Hash string `db:"hash"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetDocumentTextExtractionByHash
|
|
|
|
|
//
|
2025-04-02 18:50:03 +00:00
|
|
|
// SELECT id FROM currentTextEntries WHERE cleanId = $1 and hash = $2
|
|
|
|
|
func (q *Queries) GetDocumentTextExtractionByHash(ctx context.Context, arg *GetDocumentTextExtractionByHashParams) (uuid.UUID, error) {
|
2025-03-20 11:06:41 +00:00
|
|
|
row := q.db.QueryRow(ctx, getDocumentTextExtractionByHash, arg.Cleanentryid, arg.Hash)
|
2025-04-02 18:50:03 +00:00
|
|
|
var id uuid.UUID
|
|
|
|
|
err := row.Scan(&id)
|
|
|
|
|
return id, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getDocumentTextTrigger = `-- name: GetDocumentTextTrigger :one
|
|
|
|
|
SELECT dt.id, dt.cleanId, dt.version, dt.textractJobId, dc.documentId
|
|
|
|
|
from documentTextTriggerExtractions as dt
|
|
|
|
|
join documentCleans as dc on dt.cleanId = dc.id
|
|
|
|
|
where dt.id = $1
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type GetDocumentTextTriggerRow struct {
|
|
|
|
|
ID uuid.UUID `db:"id"`
|
|
|
|
|
Cleanid uuid.UUID `db:"cleanid"`
|
|
|
|
|
Version int64 `db:"version"`
|
|
|
|
|
Textractjobid *string `db:"textractjobid"`
|
|
|
|
|
Documentid uuid.UUID `db:"documentid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetDocumentTextTrigger
|
|
|
|
|
//
|
|
|
|
|
// SELECT dt.id, dt.cleanId, dt.version, dt.textractJobId, dc.documentId
|
|
|
|
|
// from documentTextTriggerExtractions as dt
|
|
|
|
|
// join documentCleans as dc on dt.cleanId = dc.id
|
|
|
|
|
// where dt.id = $1
|
|
|
|
|
func (q *Queries) GetDocumentTextTrigger(ctx context.Context, triggerid uuid.UUID) (*GetDocumentTextTriggerRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, getDocumentTextTrigger, triggerid)
|
|
|
|
|
var i GetDocumentTextTriggerRow
|
2025-03-20 11:06:41 +00:00
|
|
|
err := row.Scan(
|
|
|
|
|
&i.ID,
|
2025-04-02 18:50:03 +00:00
|
|
|
&i.Cleanid,
|
2025-03-20 11:06:41 +00:00
|
|
|
&i.Version,
|
2025-04-02 18:50:03 +00:00
|
|
|
&i.Textractjobid,
|
|
|
|
|
&i.Documentid,
|
2025-03-20 11:06:41 +00:00
|
|
|
)
|
|
|
|
|
return &i, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-05 19:49:03 +00:00
|
|
|
const getTextEntryByDocId = `-- name: GetTextEntryByDocId :one
|
2025-04-02 18:50:03 +00:00
|
|
|
SELECT id, documentId, bucket, key, hash, cleanId,
|
|
|
|
|
triggerId, textractJobId, triggerVersion, extractionVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
FROM currentTextEntries
|
|
|
|
|
WHERE documentId = $1
|
2025-02-07 14:15:06 +00:00
|
|
|
`
|
|
|
|
|
|
2025-03-05 19:49:03 +00:00
|
|
|
// GetTextEntryByDocId
|
2025-02-07 14:15:06 +00:00
|
|
|
//
|
2025-04-02 18:50:03 +00:00
|
|
|
// SELECT id, documentId, bucket, key, hash, cleanId,
|
|
|
|
|
// triggerId, textractJobId, triggerVersion, extractionVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
// FROM currentTextEntries
|
|
|
|
|
// WHERE documentId = $1
|
2025-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid uuid.UUID) (*Currenttextentry, error) {
|
2025-03-05 19:49:03 +00:00
|
|
|
row := q.db.QueryRow(ctx, getTextEntryByDocId, documentid)
|
2025-02-20 19:02:44 +00:00
|
|
|
var i Currenttextentry
|
2025-02-11 15:22:59 +00:00
|
|
|
err := row.Scan(
|
2025-02-20 19:02:44 +00:00
|
|
|
&i.ID,
|
2025-02-11 15:22:59 +00:00
|
|
|
&i.Documentid,
|
|
|
|
|
&i.Bucket,
|
|
|
|
|
&i.Key,
|
2025-03-20 11:06:41 +00:00
|
|
|
&i.Hash,
|
2025-04-02 18:50:03 +00:00
|
|
|
&i.Cleanid,
|
|
|
|
|
&i.Triggerid,
|
|
|
|
|
&i.Textractjobid,
|
|
|
|
|
&i.Triggerversion,
|
|
|
|
|
&i.Extractionversion,
|
2025-02-11 15:22:59 +00:00
|
|
|
)
|
2025-02-07 14:15:06 +00:00
|
|
|
return &i, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 12:44:09 +00:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 14:15:06 +00:00
|
|
|
const isDocumentTextExtracted = `-- name: IsDocumentTextExtracted :one
|
|
|
|
|
SELECT EXISTS(
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
2025-02-07 14:15:06 +00:00
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// IsDocumentTextExtracted
|
|
|
|
|
//
|
|
|
|
|
// SELECT EXISTS(
|
2025-02-20 19:02:44 +00:00
|
|
|
// SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
2025-02-07 14:15:06 +00:00
|
|
|
// )
|
2025-03-20 11:06:41 +00:00
|
|
|
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid uuid.UUID) (bool, error) {
|
2025-02-07 14:15:06 +00:00
|
|
|
row := q.db.QueryRow(ctx, isDocumentTextExtracted, documentid)
|
|
|
|
|
var exists bool
|
|
|
|
|
err := row.Scan(&exists)
|
|
|
|
|
return exists, err
|
|
|
|
|
}
|