Skip to main content

Class: BookRepository

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

Repository for Book module databases (book_*.db)

This repository handles ALL operations for a book database:

  • Module information (metadata about the book)
  • Book sections (hierarchical table of contents and content)
  • Scripture references (verses mentioned in the book)

Example

const bookDb = new SqliteProvider('data/modules/book_theology.db');
const repo = new BookRepository(bookDb);

// Get module info
const info = repo.getModuleInfo();
console.log(info.getDisplayName()); // "Systematic Theology by Louis Berkhof"

// Get table of contents
const topSections = repo.getTopLevelSections();

Extends

Implements

Constructors

Constructor

new BookRepository(sql): BookRepository

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

Parameters

sql

ISql

Returns

BookRepository

Overrides

BaseModuleRepository.constructor

Methods

createScriptureReference()

createScriptureReference(reference): ScriptureReference

Defined in: Data/Repositories/BookRepository.ts:572

Create a scripture reference.

Writes to the unified verse_link table on a v2 module; falls back to the legacy scripture_reference table on a v1 module so locally-built modules still import. Pass-2 deletion point for the fallback.

Parameters

reference

ScriptureReference

Returns

ScriptureReference

Implementation of

IBookRepository.createScriptureReference


createSection()

createSection(section): BookSection

Defined in: Data/Repositories/BookRepository.ts:506

Create a new book section

Parameters

section

BookSection

Returns

BookSection

Implementation of

IBookRepository.createSection


deleteScriptureReference()

deleteScriptureReference(referenceId): boolean

Defined in: Data/Repositories/BookRepository.ts:612

Delete a scripture reference (by link_id on v2, reference_id on v1).

Parameters

referenceId

number

Returns

boolean

Implementation of

IBookRepository.deleteScriptureReference


deleteSection()

deleteSection(sectionId): boolean

Defined in: Data/Repositories/BookRepository.ts:557

Delete a book section (and all its children via CASCADE)

Parameters

sectionId

number

Returns

boolean

Implementation of

IBookRepository.deleteSection


getAllSections()

getAllSections(): BookSection[]

Defined in: Data/Repositories/BookRepository.ts:173

Get all sections (for tree view or search)

Returns

BookSection[]

Implementation of

IBookRepository.getAllSections


getAllSectionSummaries()

getAllSectionSummaries(): BookSectionSummary[]

Defined in: Data/Repositories/BookRepository.ts:185

Get all section summaries (lighter weight for tree view)

Returns

BookSectionSummary[]

Implementation of

IBookRepository.getAllSectionSummaries


getModuleInfo()

getModuleInfo(): BookModuleInfo | 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

BookModuleInfo | undefined

Implementation of

IBookRepository.getModuleInfo

Inherited from

BaseModuleRepository.getModuleInfo


getNextSection()

getNextSection(currentSectionId): BookSection | undefined

Defined in: Data/Repositories/BookRepository.ts:229

Get the next section in reading order (depth-first traversal)

Parameters

currentSectionId

number

Returns

BookSection | undefined

Implementation of

IBookRepository.getNextSection


getParentSection()

getParentSection(currentSectionId): BookSection | undefined

Defined in: Data/Repositories/BookRepository.ts:317

Get the parent section of the current section

Parameters

currentSectionId

number

Returns

BookSection | undefined

Implementation of

IBookRepository.getParentSection


getPreviousSection()

getPreviousSection(currentSectionId): BookSection | undefined

Defined in: Data/Repositories/BookRepository.ts:272

Get the previous section in reading order

Parameters

currentSectionId

number

Returns

BookSection | undefined

Implementation of

IBookRepository.getPreviousSection


getScriptureReferences()

getScriptureReferences(sectionId): ScriptureReference[]

Defined in: Data/Repositories/BookRepository.ts:337

Get all scripture references mentioned in a specific section.

v2 reads the unified verse_link table (source_type='book_section'). v1 COMPAT: reads the legacy scripture_reference table. Pass-2 deletion point for the fallback.

Parameters

sectionId

number

Returns

ScriptureReference[]

Implementation of

IBookRepository.getScriptureReferences


getScriptureReferencesForRange()

getScriptureReferencesForRange(startVerseId, endVerseId): ScriptureReference[]

Defined in: Data/Repositories/BookRepository.ts:479

Get all scripture references for a verse range. Reads verse_link on v2 modules, scripture_reference on v1.

Parameters

startVerseId

number

endVerseId

number

Returns

ScriptureReference[]

Implementation of

IBookRepository.getScriptureReferencesForRange


getSection()

getSection(sectionId): BookSection | undefined

Defined in: Data/Repositories/BookRepository.ts:134

Get a book section by ID

Parameters

sectionId

number

Returns

BookSection | undefined

Implementation of

IBookRepository.getSection


getSectionsByParent()

getSectionsByParent(parentSectionId): BookSection[]

Defined in: Data/Repositories/BookRepository.ts:159

Get all child sections of a parent section

Parameters

parentSectionId

number

Returns

BookSection[]

Implementation of

IBookRepository.getSectionsByParent


getSectionsReferencingVerse()

getSectionsReferencingVerse(verseId): BookSection[]

Defined in: Data/Repositories/BookRepository.ts:366

Get all sections that reference a specific verse. Reads verse_link on v2 modules, scripture_reference on v1.

Parameters

verseId

number

Returns

BookSection[]

Implementation of

IBookRepository.getSectionsReferencingVerse


getTopLevelSections()

getTopLevelSections(): BookSection[]

Defined in: Data/Repositories/BookRepository.ts:146

Get all top-level sections (sections with no parent)

Returns

BookSection[]

Implementation of

IBookRepository.getTopLevelSections


getVerseLinksForSection()

getVerseLinksForSection(sectionId): VerseLinkRecord[]

Defined in: Data/Repositories/BookRepository.ts:358

Get all verse links carried by a section, in the unified v2 shape. Empty on a v1 module — use getScriptureReferences for version-agnostic access.

Parameters

sectionId

number

Returns

VerseLinkRecord[]

Implementation of

IBookRepository.getVerseLinksForSection


getVerseReferencesWithSections()

getVerseReferencesWithSections(verseId): object[]

Defined in: Data/Repositories/BookRepository.ts:437

Get scripture references for a verse with their section titles. Used by VerseLinksService to display book references without N+1 queries.

Parameters

verseId

number

Returns

object[]

Implementation of

IBookRepository.getVerseReferencesWithSections


getVerseReferencesWithSectionsForRange()

getVerseReferencesWithSectionsForRange(startVerseId, endVerseId): object[]

Defined in: Data/Repositories/BookRepository.ts:398

Bulk variant of getVerseReferencesWithSections: every reference whose passage overlaps the inclusive range, each carrying its own passage bounds so the caller can attribute it to the individual verses it covers.

Parameters

startVerseId

number

endVerseId

number

Returns

object[]

Implementation of

IBookRepository.getVerseReferencesWithSectionsForRange


searchSections()

searchSections(query, options?): BookSection[]

Defined in: Data/Repositories/BookRepository.ts:207

Search book sections using full-text search

Parameters

query

string

options?
limit?

number

Returns

BookSection[]

Implementation of

IBookRepository.searchSections


updateModuleInfo()

updateModuleInfo(info): void

Defined in: Data/Repositories/BookRepository.ts:104

Update the module information

Parameters

info

BookModuleInfo

Returns

void

Implementation of

IBookRepository.updateModuleInfo


updateSection()

updateSection(section): BookSection

Defined in: Data/Repositories/BookRepository.ts:529

Update an existing book section

Parameters

section

BookSection

Returns

BookSection

Implementation of

IBookRepository.updateSection