2025-03-20 11:06:41 +00:00
|
|
|
-- name: IsDocumentTextExtracted :one
|
|
|
|
|
SELECT EXISTS(
|
|
|
|
|
SELECT 1 FROM currentTextEntries WHERE documentId = @documentId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- name: GetDocumentTextExtractionByHash :one
|
2025-04-02 18:50:03 +00:00
|
|
|
SELECT id FROM currentTextEntries WHERE cleanId = @cleanEntryId and hash = @hash;
|
|
|
|
|
|
2025-04-08 12:44:09 +00:00
|
|
|
-- name: GetTextractOutputCurrentPart :one
|
|
|
|
|
WITH client as (
|
|
|
|
|
select id from clients where id = @clientId
|
|
|
|
|
),
|
|
|
|
|
parts as (
|
2025-04-22 14:40:16 +00:00
|
|
|
SELECT extract.part
|
2025-04-08 12:44:09 +00:00
|
|
|
FROM client as c
|
|
|
|
|
JOIN documents as docs on docs.clientId = c.id
|
|
|
|
|
JOIN documentCleans as clean on docs.id = clean.documentId
|
2025-04-22 14:40:16 +00:00
|
|
|
JOIN documentTextExtractions as extract
|
|
|
|
|
on extract.cleanId = clean.id
|
|
|
|
|
WHERE date(extract.createdAt) = date(@queryDate)
|
2025-04-08 12:44:09 +00:00
|
|
|
),
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
-- name: GetTextOutCurrentPart :one
|
|
|
|
|
WITH client as (
|
|
|
|
|
select id from clients where id = @clientId
|
|
|
|
|
),
|
|
|
|
|
parts as (
|
2025-04-22 14:40:16 +00:00
|
|
|
SELECT extract.part
|
2025-04-08 12:44:09 +00:00
|
|
|
FROM client as c
|
|
|
|
|
JOIN documents as docs on docs.clientId = c.id
|
|
|
|
|
JOIN documentCleans as clean on docs.id = clean.documentId
|
2025-04-22 14:40:16 +00:00
|
|
|
JOIN documentTextExtractions extract ON extract.cleanId = clean.id
|
|
|
|
|
WHERE date(extract.createdAt) = date(@queryDate)
|
2025-04-08 12:44:09 +00:00
|
|
|
),
|
|
|
|
|
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;
|
2025-04-02 18:50:03 +00:00
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
-- name: AddDocumentText :one
|
2025-04-08 12:44:09 +00:00
|
|
|
INSERT INTO documentTextExtractions
|
2025-04-22 14:40:16 +00:00
|
|
|
(cleanId, bucket, key, hash, createdAt, part)
|
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
2025-04-08 12:44:09 +00:00
|
|
|
returning id;
|
2025-03-20 11:06:41 +00:00
|
|
|
|
|
|
|
|
-- name: AddDocumentTextEntry :exec
|
2025-04-08 12:44:09 +00:00
|
|
|
INSERT INTO documentTextExtractionEntries
|
2025-04-22 14:40:16 +00:00
|
|
|
(textId, version)
|
|
|
|
|
VALUES ($1, $2);
|
2025-03-20 11:06:41 +00:00
|
|
|
|
|
|
|
|
-- name: GetTextEntryByDocId :one
|
2025-04-22 14:40:16 +00:00
|
|
|
SELECT id, documentId, bucket, key, hash, cleanId, extractionVersion
|
2025-03-20 11:06:41 +00:00
|
|
|
FROM currentTextEntries
|
|
|
|
|
WHERE documentId = @documentId;
|