81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
47 lines
1.3 KiB
SQL
47 lines
1.3 KiB
SQL
-- name: GetDocumentSummary :one
|
|
SELECT id, clientId, hash FROM documents WHERE id = $1;
|
|
|
|
-- name: GetDocumentExternal :one
|
|
WITH
|
|
docs AS (
|
|
SELECT id, hash, clientId
|
|
FROM documents
|
|
WHERE id = @documentId
|
|
),
|
|
namedResults AS (
|
|
SELECT
|
|
q.name,
|
|
dd.id,
|
|
d.value
|
|
FROM currentCollectorQueries AS q
|
|
JOIN docs as dd on dd.clientId = q.clientId
|
|
LEFT JOIN listValidDocumentResults(@documentId) AS d
|
|
ON d.queryId = q.queryId and q.name is not null
|
|
)
|
|
SELECT
|
|
d.id,
|
|
d.clientId,
|
|
d.hash,
|
|
COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
|
FROM docs AS d
|
|
LEFT JOIN namedResults AS r ON d.id = r.id
|
|
GROUP BY d.id, d.clientId, d.hash;
|
|
|
|
-- name: ListDocumentsByClient :many
|
|
SELECT id, hash from documents where clientId = @clientId;
|
|
|
|
-- name: CreateDocument :one
|
|
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id;
|
|
|
|
-- name: AddDocumentEntry :exec
|
|
INSERT INTO documentEntries (documentId, bucket, key) VALUES ($1, $2, $3);
|
|
|
|
-- name: GetDocumentEntry :one
|
|
SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1;
|
|
|
|
-- name: GetDocumentIDByHash :one
|
|
SELECT id FROM documents WHERE hash = $1 and clientId = $2;
|
|
|
|
-- name: ListDocumentIDsBatch :many
|
|
SELECT id, totalCount FROM listDocumentIDs(@clientId, @batchSize, @pageOffset);
|