Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: document_text.sql
package store
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getCurrentDocumentTextSource = `-- name: GetCurrentDocumentTextSource :one
SELECT document.tenant_id::text AS tenant_id,
(CASE WHEN document.format='blocknote' THEN 'native_body' ELSE 'file_version' END)::text AS source_kind,
(CASE WHEN document.format='blocknote' THEN body.seq::text ELSE document.current_version_id END)::text AS source_id
FROM documents document
LEFT JOIN document_bodies body ON body.document_id=document.id
WHERE document.id=$1::text AND document.status='active'
AND (CASE WHEN document.format='blocknote' THEN body.seq::text ELSE document.current_version_id END) IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM document_texts text
WHERE text.document_id=document.id AND document.format<>'blocknote'
AND text.source_kind='file_version' AND text.source_id=document.current_version_id
AND text.status='ready')
`
type GetCurrentDocumentTextSourceRow struct {
TenantID string `json:"tenant_id"`
SourceKind string `json:"source_kind"`
SourceID string `json:"source_id"`
}
// Returns the Document's current version: its body sequence when native, its
// current Version otherwise. A Version is immutable, so one whose text is
// already ready returns no row: TeamHub writes the text of the Markdown
// Versions it generates itself in the transaction that makes them current.
func (q *Queries) GetCurrentDocumentTextSource(ctx context.Context, documentID string) (GetCurrentDocumentTextSourceRow, error) {
row := q.db.QueryRow(ctx, getCurrentDocumentTextSource, documentID)
var i GetCurrentDocumentTextSourceRow
err := row.Scan(&i.TenantID, &i.SourceKind, &i.SourceID)
return i, err
}
const upsertDocumentText = `-- name: UpsertDocumentText :execrows
WITH current AS (
SELECT document.id AS document_id, document.tenant_id,
(CASE WHEN document.format='blocknote' THEN 'native_body' ELSE 'file_version' END)::text AS source_kind,
(CASE WHEN document.format='blocknote' THEN body.seq::text ELSE document.current_version_id END)::text AS source_id
FROM documents document
LEFT JOIN document_bodies body ON body.document_id=document.id
WHERE document.id=$8::text AND document.status='active'
)
INSERT INTO document_texts (document_id, tenant_id, source_kind, source_id, status,
markdown, markdown_sha256, search_text,
longest_line_bytes, updated_at)
SELECT current.document_id, current.tenant_id, current.source_kind, current.source_id,
$1::text, $2::text, $3::text,
$4::text,
$5::bigint, clock_timestamp()
FROM current
WHERE current.source_kind=$6::text AND current.source_id=$7::text
ON CONFLICT (document_id) DO UPDATE
SET source_kind=EXCLUDED.source_kind, source_id=EXCLUDED.source_id, status=EXCLUDED.status,
markdown=EXCLUDED.markdown, markdown_sha256=EXCLUDED.markdown_sha256,
search_text=EXCLUDED.search_text,
longest_line_bytes=EXCLUDED.longest_line_bytes, updated_at=EXCLUDED.updated_at
`
type UpsertDocumentTextParams struct {
Status string `json:"status"`
Markdown string `json:"markdown"`
MarkdownSha256 pgtype.Text `json:"markdown_sha256"`
SearchText string `json:"search_text"`
LongestLineBytes int64 `json:"longest_line_bytes"`
SourceKind string `json:"source_kind"`
SourceID string `json:"source_id"`
DocumentID string `json:"document_id"`
}
// Writes only while the Document's current version is still the one the sync
// extracted. A zero row count means a newer version superseded this sync, and
// that version has queued its own sync.
func (q *Queries) UpsertDocumentText(ctx context.Context, arg UpsertDocumentTextParams) (int64, error) {
result, err := q.db.Exec(ctx, upsertDocumentText,
arg.Status,
arg.Markdown,
arg.MarkdownSha256,
arg.SearchText,
arg.LongestLineBytes,
arg.SourceKind,
arg.SourceID,
arg.DocumentID,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}