Skip to main content

Class: CommentaryRepository

Defined in: Data/Repositories/CommentaryRepository.ts:39

Repository for Commentary module databases (commentary_*.db)

This repository handles ALL operations for a commentary database:

  • Module information (metadata about the commentary)
  • Commentary entries (the actual commentary text)
  • Cross-references (if included)

Example

const mhcDb = new SqliteProvider('data/modules/commentary_mhc.db');
const repo = new CommentaryRepository(mhcDb);

// Get module info
const info = repo.getModuleInfo();
console.log(info.getDisplayName()); // "Matthew Henry's Commentary by Matthew Henry"

// Get commentary for a verse
const entries = repo.getEntriesForVerse(43003016); // John 3:16

Extends

Implements

Constructors

Constructor

new CommentaryRepository(sql): CommentaryRepository

Defined in: Data/Repositories/CommentaryRepository.ts:42

Parameters

sql

ISql

Returns

CommentaryRepository

Overrides

BaseModuleRepository.constructor

Methods

createEntry()

createEntry(entry): CommentaryEntry

Defined in: Data/Repositories/CommentaryRepository.ts:354

Create a new commentary entry

Parameters

entry

CommentaryEntry

Returns

CommentaryEntry

Implementation of

ICommentaryRepository.createEntry


deleteEntry()

deleteEntry(entryId): boolean

Defined in: Data/Repositories/CommentaryRepository.ts:409

Delete a commentary entry

Parameters

entryId

number

Returns

boolean

Implementation of

ICommentaryRepository.deleteEntry


getAllEntrySummaries()

getAllEntrySummaries(): CommentaryEntrySummary[]

Defined in: Data/Repositories/CommentaryRepository.ts:454

Get all entry summaries for tree view/navigation

Returns

CommentaryEntrySummary[]

Implementation of

ICommentaryRepository.getAllEntrySummaries


getBestEntryAnchorsForRange()

getBestEntryAnchorsForRange(startVerseId, endVerseId): CommentaryEntryAnchor[]

Defined in: Data/Repositories/CommentaryRepository.ts:204

Bulk variant of getBestEntryForVerse: every entry ANCHOR (no content blob) whose range overlaps the inclusive verse range, ordered by verse_id_start.

VerseLinksService.getBatchVerseLinks reconstructs the per-verse answer by taking the first row that covers each verse, which is exactly what getBestEntryForVerse's ORDER BY verse_id_start LIMIT 1 returns. Reading anchors rather than entries matters: a module like Matthew Henry stores the same ~73 KB chapter blob on every verse row it covers, so a SELECT * over a chapter reads tens of megabytes to answer "is there an entry here".

Parameters

startVerseId

number

endVerseId

number

Returns

CommentaryEntryAnchor[]

Implementation of

ICommentaryRepository.getBestEntryAnchorsForRange


getBestEntryForVerse()

getBestEntryForVerse(verseId): CommentaryEntry | undefined

Defined in: Data/Repositories/CommentaryRepository.ts:143

Get the single best-match entry for a verse (first match by verse_id_start). Used by VerseLinksService for quick presence checks.

Parameters

verseId

number

Returns

CommentaryEntry | undefined

Implementation of

ICommentaryRepository.getBestEntryForVerse


getEntriesByLevel()

getEntriesByLevel(level): CommentaryEntry[]

Defined in: Data/Repositories/CommentaryRepository.ts:130

Get entries by level (book, chapter, passage, verse)

Parameters

level

"book" | "verse" | "passage" | "chapter"

Returns

CommentaryEntry[]

Implementation of

ICommentaryRepository.getEntriesByLevel


getEntriesForRange()

getEntriesForRange(startVerseId, endVerseId): CommentaryEntry[]

Defined in: Data/Repositories/CommentaryRepository.ts:278

Get entries for a verse range

Parameters

startVerseId

number

endVerseId

number

Returns

CommentaryEntry[]

Implementation of

ICommentaryRepository.getEntriesForRange


getEntriesForVerse()

getEntriesForVerse(verseId): CommentaryEntry[]

Defined in: Data/Repositories/CommentaryRepository.ts:115

Get all commentary entries for a specific verse

Parameters

verseId

number

Returns

CommentaryEntry[]

Implementation of

ICommentaryRepository.getEntriesForVerse


getEntry()

getEntry(entryId): CommentaryEntry | undefined

Defined in: Data/Repositories/CommentaryRepository.ts:103

Get a commentary entry by ID

Parameters

entryId

number

Returns

CommentaryEntry | undefined

Implementation of

ICommentaryRepository.getEntry


getEntryIdsReferencingVerse()

getEntryIdsReferencingVerse(verseId): number[]

Defined in: Data/Repositories/CommentaryRepository.ts:92

Entry ids whose verse_link rows reference the given verse.

Parameters

verseId

number

Returns

number[]

Implementation of

ICommentaryRepository.getEntryIdsReferencingVerse


getEntrySummariesForRange()

getEntrySummariesForRange(startVerseId, endVerseId): CommentaryEntrySummary[]

Defined in: Data/Repositories/CommentaryRepository.ts:291

Anchors and sizes for a range, without the content blobs.

For callers that only need to know what exists and how big it is — the chapter-overview endpoint and the client's prefetch budget. Reading full entries for that is enormously wasteful: a module like Matthew Henry stores the same ~73 KB chapter blob on every verse row it covers, so a SELECT * over one chapter of every installed commentary reads tens of megabytes to compute a handful of word counts.

Parameters

startVerseId

number

endVerseId

number

Returns

CommentaryEntrySummary[]

Implementation of

ICommentaryRepository.getEntrySummariesForRange


getModuleInfo()

getModuleInfo(): CommentaryModuleInfo | undefined

Defined in: Data/Repositories/BaseModuleRepository.ts:137

Get module metadata from the module_info table. Every module database has exactly one row in module_info (info_id = 1).

Returns

CommentaryModuleInfo | undefined

Implementation of

ICommentaryRepository.getModuleInfo

Inherited from

BaseModuleRepository.getModuleInfo


getNextVerseWithContent()

getNextVerseWithContent(currentVerseId): number | undefined

Defined in: Data/Repositories/CommentaryRepository.ts:424

Get the next verse ID that has commentary content

Parameters

currentVerseId

number

Returns

number | undefined

Implementation of

ICommentaryRepository.getNextVerseWithContent


getPreviousVerseWithContent()

getPreviousVerseWithContent(currentVerseId): number | undefined

Defined in: Data/Repositories/CommentaryRepository.ts:439

Get the previous verse ID that has commentary content

Parameters

currentVerseId

number

Returns

number | undefined

Implementation of

ICommentaryRepository.getPreviousVerseWithContent


getVerseLinksForEntry()

getVerseLinksForEntry(entryId): VerseLinkRecord[]

Defined in: Data/Repositories/CommentaryRepository.ts:87

Scripture references carried by a commentary entry.

v2 reads the unified verse_link table (source_type='commentary_entry'). Returns an empty array on a v1 module, where such references are still unparsed HTML anchors inside content (see ModuleFormat-v2-Plan WS-9).

Parameters

entryId

number

Returns

VerseLinkRecord[]

Implementation of

ICommentaryRepository.getVerseLinksForEntry


getVerseMentionRowsForRange()

getVerseMentionRowsForRange(startVerseId, endVerseId): CommentaryMentionRow[]

Defined in: Data/Repositories/CommentaryRepository.ts:232

Bulk variant of getVerseMentions: one row per (entry, verse-link) pair whose link range overlaps [startVerseId, endVerseId].

Left un-aggregated on purpose — the per-verse counts getVerseMentions returns depend on which verse is being asked about, and a link row may span several of the verses in the range.

Parameters

startVerseId

number

endVerseId

number

Returns

CommentaryMentionRow[]

Implementation of

ICommentaryRepository.getVerseMentionRowsForRange


getVerseMentions()

getVerseMentions(verseId): object[]

Defined in: Data/Repositories/CommentaryRepository.ts:163

Get entries from other verses that mention/reference this verse. Returns aggregated counts per entry.

v2 reads the unified verse_link table. v1 COMPAT: falls back to the verse_reference table, which in practice exists in zero shipped commentary modules (ModuleFormat-v2-Plan §2) — the fallback is retained only so a locally-built v1 module keeps working. Pass-2 deletion point.

Parameters

verseId

number

Returns

object[]

Implementation of

ICommentaryRepository.getVerseMentions


searchEntries()

searchEntries(query, options?): CommentaryEntry[]

Defined in: Data/Repositories/CommentaryRepository.ts:321

Search commentary entries

Note: The FTS5 index contains HTML content, so phrase searches like "Man had no claim" might fail if there are HTML tags between words. We convert phrase queries to NEAR queries to handle this case.

Parameters

query

string

options?
limit?

number

Returns

CommentaryEntry[]

Implementation of

ICommentaryRepository.searchEntries


updateEntry()

updateEntry(entry): CommentaryEntry

Defined in: Data/Repositories/CommentaryRepository.ts:379

Update an existing commentary entry

Parameters

entry

CommentaryEntry

Returns

CommentaryEntry

Implementation of

ICommentaryRepository.updateEntry


updateModuleInfo()

updateModuleInfo(info): void

Defined in: Data/Repositories/CommentaryRepository.ts:55

Update the module information. The v2 identity + provenance block (WS-4) is written when the connected database has those columns.

Parameters

info

CommentaryModuleInfo

Returns

void

Implementation of

ICommentaryRepository.updateModuleInfo