-- name: IsDocumentTextExtracted :one
SELECT EXISTS(
    SELECT 1 FROM currentTextEntries WHERE documentId = @documentId
);

-- name: GetDocumentTextExtractionByHash :one
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
    FROM currentTextEntries
    WHERE cleanEntryId = @cleanEntryId and hash = @hash;

-- name: AddDocumentText :one
INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id;

-- name: AddDocumentTextEntry :exec
INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2);

-- name: GetTextEntryByDocId :one
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
    FROM currentTextEntries
    WHERE documentId = @documentId;
