db

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeminiBatchPrepared          = "prepared"
	GeminiBatchUploadUnknown     = "upload_unknown"
	GeminiBatchUploaded          = "uploaded"
	GeminiBatchSubmissionUnknown = "submission_unknown"
	GeminiBatchPending           = "pending"
	GeminiBatchRunning           = "running"
	GeminiBatchCancelling        = "cancelling"
	GeminiBatchSucceeded         = "succeeded"
	GeminiBatchFailed            = "failed"
	GeminiBatchCancelled         = "cancelled"
	GeminiBatchExpired           = "expired"

	GeminiRequestAssigned  = "assigned"
	GeminiRequestStaged    = "staged"
	GeminiRequestRetryable = "retryable"
	GeminiRequestBlocked   = "blocked"
)

Variables

View Source
var ErrGeminiBatchSubmissionClaimLost = errors.New("Gemini batch submission claim lost")

Functions

This section is empty.

Types

type Content

type Content struct {
	ID         int64
	Checksum   string
	PageCount  int
	OCRPending bool
}

type DB

type DB struct {
	*sql.DB
}

func Open

func Open(path string) (*DB, error)

func (*DB) AllDocuments

func (db *DB) AllDocuments() ([]Document, error)

func (*DB) AllStats

func (db *DB) AllStats() (docCount int, totalPages int, err error)

func (*DB) BlockGeminiBatchRequests added in v0.3.0

func (db *DB) BlockGeminiBatchRequests(batchID int64, message string, now time.Time) error

func (*DB) BlockGeminiRequest added in v0.3.0

func (db *DB) BlockGeminiRequest(requestID int64, message string, now time.Time) error

func (*DB) BlockUnownedGeminiRequest added in v0.3.0

func (db *DB) BlockUnownedGeminiRequest(requestID int64, message string, now time.Time) error

func (*DB) BlockedGeminiRequests added in v0.3.0

func (db *DB) BlockedGeminiRequests() ([]GeminiBatchRequest, error)

func (*DB) ClaimGeminiBatchSubmission added in v0.4.0

func (db *DB) ClaimGeminiBatchSubmission(
	batchID int64,
	model string,
	inputPrice, outputPrice int64,
	now time.Time,
) error

ClaimGeminiBatchSubmission atomically reserves the non-idempotent CreateBatch call. submission_unknown makes a crash after the claim recoverable by remote adoption, while snapshotting the submitted model and prices keeps later decoding and billing tied to the attempt rather than to changing production defaults.

func (*DB) CleanupOrphanContents

func (db *DB) CleanupOrphanContents() (int, error)

func (*DB) CompleteGeminiDirectRequest added in v0.3.0

func (db *DB) CompleteGeminiDirectRequest(
	requestID int64,
	pages []PageInput,
	knownCost int64,
	indeterminate bool,
	now time.Time,
) (contentComplete bool, err error)

func (*DB) ContentOCRCoverage added in v0.3.0

func (db *DB) ContentOCRCoverage(contentID int64) (int, []ModelCount, error)

func (*DB) CopyContentPages added in v0.3.0

func (db *DB) CopyContentPages(sourceContentID, targetContentID int64) (err error)

func (*DB) CountGeminiCleanup added in v0.3.0

func (db *DB) CountGeminiCleanup() (int, error)

func (*DB) CountTrackedGeminiBatches added in v0.3.0

func (db *DB) CountTrackedGeminiBatches() (int, error)

func (*DB) CreateBlockedGeminiRequest added in v0.3.0

func (db *DB) CreateBlockedGeminiRequest(plan GeminiRequestPlan, message string, now time.Time) (int64, error)

func (*DB) CreateGeminiBatch added in v0.3.0

func (db *DB) CreateGeminiBatch(
	displayName, model string,
	inputPrice, outputPrice int64,
	replacementOf *int64,
	plans []GeminiRequestPlan,
	now time.Time,
) (int64, error)

func (*DB) CreateGeminiBatchForRequests added in v0.3.0

func (db *DB) CreateGeminiBatchForRequests(
	displayName, model string,
	inputPrice, outputPrice int64,
	replacementOf *int64,
	requestIDs []int64,
	now time.Time,
) (batchID int64, err error)

func (*DB) CreateGeminiBatchWork added in v0.3.0

func (db *DB) CreateGeminiBatchWork(
	creations []GeminiBatchCreation,
	blocked []GeminiBlockedRequest,
	now time.Time,
) (batchIDs []int64, err error)

func (*DB) DeleteGeminiCleanup added in v0.3.0

func (db *DB) DeleteGeminiCleanup(cleanupID int64) error

func (*DB) DetachGeminiBatchForReplacement added in v0.3.0

func (db *DB) DetachGeminiBatchForReplacement(
	batchID int64,
	message string,
	now time.Time,
) (retryable []int64, err error)

func (*DB) DetachGeminiBatchRequestsForRegeneration added in v0.3.0

func (db *DB) DetachGeminiBatchRequestsForRegeneration(batchID int64, message string, now time.Time) error

func (*DB) FinalizeGeminiBatch added in v0.3.0

func (db *DB) FinalizeGeminiBatch(batchID int64, now time.Time) (cleanup []GeminiCleanup, err error)

func (*DB) ForgetGeminiBatch added in v0.3.0

func (db *DB) ForgetGeminiBatch(batchID int64, now time.Time) (batch *GeminiBatch, err error)

func (*DB) GeminiRequestByID added in v0.3.0

func (db *DB) GeminiRequestByID(requestID int64) (*GeminiBatchRequest, error)

func (*DB) GeminiRequestsForBatch added in v0.3.0

func (db *DB) GeminiRequestsForBatch(batchID int64) ([]GeminiBatchRequest, error)

func (*DB) GetContentByChecksum

func (db *DB) GetContentByChecksum(checksum string) (*Content, error)

func (*DB) GetContentByID added in v0.3.0

func (db *DB) GetContentByID(contentID int64) (*Content, error)

func (*DB) GetDocumentByPath

func (db *DB) GetDocumentByPath(path string) (*Document, error)

func (*DB) GetDocumentMetadataByPath added in v0.3.0

func (db *DB) GetDocumentMetadataByPath(path string) (*Document, error)

func (*DB) GetDocumentPathForContent

func (db *DB) GetDocumentPathForContent(contentID int64) (string, error)

func (*DB) GetDocumentPathsForContent added in v0.3.0

func (db *DB) GetDocumentPathsForContent(contentID int64) ([]string, error)

func (*DB) GetGeminiBatch added in v0.3.0

func (db *DB) GetGeminiBatch(batchID int64) (*GeminiBatch, error)

func (*DB) GetPageMarkdownByPathAndIndex

func (db *DB) GetPageMarkdownByPathAndIndex(path string, pageIndex int) (string, error)

OCR-backed reads follow the same all-pages-visible-at-once rule as FTS.

func (*DB) GetPagesMarkdownByPathAndRange

func (db *DB) GetPagesMarkdownByPathAndRange(path string, startInclusive, endInclusive int) ([]PageRecord, error)

func (*DB) InsertContent

func (db *DB) InsertContent(checksum string, pageCount int) (int64, error)

func (*DB) InsertDocument

func (db *DB) InsertDocument(path string, contentID int64, createdAt, modifiedAt time.Time) (int64, error)

func (*DB) ListDocuments

func (db *DB) ListDocuments(opts ListOptions) ([]Document, error)

func (*DB) ListGeminiBatches added in v0.3.0

func (db *DB) ListGeminiBatches() ([]GeminiBatch, error)

func (*DB) ListGeminiCleanup added in v0.3.0

func (db *DB) ListGeminiCleanup() ([]GeminiCleanup, error)

func (*DB) MissingPageIndexes added in v0.3.0

func (db *DB) MissingPageIndexes(contentID int64) ([]int, error)

func (*DB) MissingPageRanges added in v0.3.0

func (db *DB) MissingPageRanges(contentID int64) ([]PageRange, error)

func (*DB) MissingPageRangesWithin added in v0.3.0

func (db *DB) MissingPageRangesWithin(contentID int64, start, end int) ([]PageRange, error)

func (*DB) MissingUnownedPageRanges added in v0.3.0

func (db *DB) MissingUnownedPageRanges(contentID int64) ([]PageRange, error)

func (*DB) PendingContents

func (db *DB) PendingContents() ([]Content, error)

func (*DB) PendingContentsForDirect added in v0.3.0

func (db *DB) PendingContentsForDirect() ([]Content, int, error)

func (*DB) PendingContentsForGeminiBatch added in v0.3.0

func (db *DB) PendingContentsForGeminiBatch() ([]Content, error)

func (*DB) PendingDocuments

func (db *DB) PendingDocuments() ([]Document, error)

func (*DB) PendingStats

func (db *DB) PendingStats() (docCount int, totalPages int, err error)

func (*DB) RecomputeContentPending added in v0.3.0

func (db *DB) RecomputeContentPending(contentID int64) (err error)

func (*DB) ReplaceContentPages

func (db *DB) ReplaceContentPages(contentID int64, pages []PageInput) error

ReplaceContentPages remains as a compatibility name for callers that already have a complete set. Page writes are additive: partial retries must never erase successful pages from an earlier provider or run.

func (*DB) ReplaceContentPagesDirect added in v0.3.0

func (db *DB) ReplaceContentPagesDirect(contentID int64, pages []PageInput, now time.Time) (err error)

func (*DB) RestoreDocument

func (db *DB) RestoreDocument(id int64, contentID int64, modifiedAt time.Time) error

func (*DB) RetireCompletedGeminiRequests added in v0.3.0

func (db *DB) RetireCompletedGeminiRequests() (completed int, err error)

func (*DB) RetryGeminiRequest added in v0.3.0

func (db *DB) RetryGeminiRequest(requestID int64, message string, now time.Time) (bool, error)

func (*DB) RetryableGeminiRequests added in v0.3.0

func (db *DB) RetryableGeminiRequests() ([]GeminiBatchRequest, error)

func (*DB) Search

func (db *DB) Search(query string) ([]SearchResult, error)

func (*DB) SearchWithOptions

func (db *DB) SearchWithOptions(opts SearchOptions) ([]SearchResult, error)

func (*DB) SetGeminiBatchError added in v0.3.0

func (db *DB) SetGeminiBatchError(batchID int64, message string, now time.Time) error

func (*DB) SetGeminiBatchPrepared added in v0.3.0

func (db *DB) SetGeminiBatchPrepared(batchID int64, message string, now time.Time) error

func (*DB) SetGeminiBatchRemote added in v0.3.0

func (db *DB) SetGeminiBatchRemote(
	batchID int64,
	remoteName, state, outputFileName, message string,
	now time.Time,
) error

func (*DB) SetGeminiBatchState added in v0.3.0

func (db *DB) SetGeminiBatchState(
	batchID int64,
	state, outputFileName, message string,
	now time.Time,
) error

func (*DB) SetGeminiBatchUploadUnknown added in v0.3.0

func (db *DB) SetGeminiBatchUploadUnknown(batchID int64, now time.Time) error

func (*DB) SetGeminiBatchUploaded added in v0.3.0

func (db *DB) SetGeminiBatchUploaded(batchID int64, inputFileName string, now time.Time) error

func (*DB) SetGeminiCleanupError added in v0.3.0

func (db *DB) SetGeminiCleanupError(cleanupID int64, message string, now time.Time) error

func (*DB) SoftDeleteMissing

func (db *DB) SoftDeleteMissing(seenPaths map[string]bool, roots []string) (int, error)

func (*DB) SplitGeminiRequest added in v0.3.0

func (db *DB) SplitGeminiRequest(
	requestID int64,
	leftKey, rightKey, message string,
	now time.Time,
) (requestIDs []int64, err error)

func (*DB) StageGeminiDirectRequest added in v0.3.0

func (db *DB) StageGeminiDirectRequest(
	requestID int64,
	pages []GeminiStagedPage,
	knownCost int64,
	indeterminate bool,
	now time.Time,
) error

func (*DB) StageGeminiRequest added in v0.3.0

func (db *DB) StageGeminiRequest(
	requestID int64,
	pages []GeminiStagedPage,
	inputTokens, outputTokens *int64,
	knownCost int64,
	indeterminate bool,
	now time.Time,
) error

func (*DB) UpdateDocument

func (db *DB) UpdateDocument(id int64, contentID int64, modifiedAt time.Time) error

func (*DB) UpsertContentPages added in v0.3.0

func (db *DB) UpsertContentPages(contentID int64, pages []PageInput) (err error)

func (*DB) UpsertPage

func (db *DB) UpsertPage(contentID int64, pageIndex int, markdown string) error

type Document

type Document struct {
	ID                int64
	Path              string
	ContentID         int64
	Checksum          string
	CreatedAt         time.Time
	ModifiedAt        time.Time
	PageCount         int
	OCRPagesCompleted int
	Models            []ModelCount
	OCRPending        bool
	Deleted           bool
}

type GeminiBatch added in v0.3.0

type GeminiBatch struct {
	ID             int64
	DisplayName    string
	Model          string
	RequestKeys    []string
	State          string
	InputFileName  string
	OutputFileName string
	RemoteName     string
	InputPrice     int64
	OutputPrice    int64
	ReplacementOf  *int64
	LastError      string
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type GeminiBatchCreation added in v0.3.0

type GeminiBatchCreation struct {
	DisplayName   string
	Model         string
	InputPrice    int64
	OutputPrice   int64
	ReplacementOf *int64
	Requests      []GeminiRequestPlan
}

type GeminiBatchRequest added in v0.3.0

type GeminiBatchRequest struct {
	ID                int64
	ContentID         int64
	BatchID           *int64
	RequestKey        string
	FileType          string
	PageStart         int
	PageEnd           int
	State             string
	AttemptCount      int
	ReplacementCount  int
	PreviousBatchID   *int64
	SplitDepth        int
	InputTokens       *int64
	OutputTokens      *int64
	KnownCost         int64
	CostIndeterminate bool
	LastError         string
	CreatedAt         time.Time
	UpdatedAt         time.Time
	Path              string
	Checksum          string
	PageCount         int
}

type GeminiBlockedRequest added in v0.3.0

type GeminiBlockedRequest struct {
	Plan    GeminiRequestPlan
	Message string
}

type GeminiCleanup added in v0.3.0

type GeminiCleanup struct {
	ID           int64
	ResourceKind string
	ResourceName string
	LastError    string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type GeminiRequestPlan added in v0.3.0

type GeminiRequestPlan struct {
	ContentID        int64
	RequestKey       string
	FileType         string
	PageStart        int
	PageEnd          int
	AttemptCount     int
	ReplacementCount int
	SplitDepth       int
}

type GeminiStagedPage added in v0.3.0

type GeminiStagedPage struct {
	PageIndex int
	Markdown  string
	Model     string
}

type ListOptions

type ListOptions struct {
	After  *time.Time
	Before *time.Time
	Limit  int
	Offset int
}

type ModelCount added in v0.3.0

type ModelCount struct {
	Model     *string
	PageCount int
}

type PageInput

type PageInput struct {
	PageIndex int
	Markdown  string
	Model     *string
}

type PageRange added in v0.3.0

type PageRange struct {
	Start int
	End   int
}

type PageRecord

type PageRecord struct {
	ID        int64
	ContentID int64
	PageIndex int
	Markdown  string
	Model     *string
}

type SearchOptions

type SearchOptions struct {
	Query           string
	RawFTS          string
	Mode            string
	Limit           int
	Offset          int
	IncludePathLike bool
	UseTrigram      bool
}

type SearchResult

type SearchResult struct {
	Path         string
	PageIndex    int
	PageCount    int
	Snippet      string
	Rank         float64
	SearchSource string
	Model        *string
	OCRPending   bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL