Skip to main content

Class: UserNoteRepository

Defined in: Data/Repositories/UserNoteRepository.ts:89

Repository for user note entities stored in a user database (user_*.db).

Provides CRUD operations, verse-based queries, hierarchical note trees, full-text search, and navigation helpers for the user_note table. Notes support multiple types (verse_note, document, prayer, journal) and can be linked to verses via the note_verse_link table.

Example

const userDb = new SqliteProvider('data/users/user_john.db');
const noteRepo = new UserNoteRepository(userDb);

// Get notes for a specific verse
const notes = noteRepo.getForVerse(43003016); // John 3:16

// Create a new verse note
const note = new UserNote({
verseIdStart: 43003016,
content: '<p>This verse teaches...</p>',
contentFormat: 'html',
noteType: 'verse_note',
visibility: 'private'
});
noteRepo.create(note);

Implements

Constructors

Constructor

new UserNoteRepository(sql): UserNoteRepository

Defined in: Data/Repositories/UserNoteRepository.ts:98

Parameters

sql

ISql

Returns

UserNoteRepository

Methods

countDescendants()

countDescendants(noteId): number

Defined in: Data/Repositories/UserNoteRepository.ts:474

Count all descendants (children, grandchildren, …) of a note.

user_note.parent_note_id is ON DELETE CASCADE, so deleting this note silently removes its whole subtree. Callers use this to warn/confirm before a cascade delete (A6). Returns 0 when the note has no children.

Parameters

noteId

number

Returns

number

Implementation of

IUserNoteRepository.countDescendants


create()

create(entity): UserNote

Defined in: Data/Repositories/UserNoteRepository.ts:367

Create a new note and persist it to the database. Automatically sets created_date and modified_date if not provided. Also saves any linked verses attached to the note.

Parameters

entity

UserNote

The UserNote to create (noteId will be set from the insert result)

Returns

UserNote

The same entity with noteId populated

Implementation of

IUserNoteRepository.create


delete()

delete(id): boolean

Defined in: Data/Repositories/UserNoteRepository.ts:491

Delete a note

Parameters

id

number

Returns

boolean

Implementation of

IUserNoteRepository.delete


getAll()

getAll(options?): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:126

Get all notes

Parameters

options?

RepositoryQueryOptions

Returns

UserNote[]

Implementation of

IUserNoteRepository.getAll


getAllNoteSummaries()

getAllNoteSummaries(): NoteSummary[]

Defined in: Data/Repositories/UserNoteRepository.ts:305

Get all note summaries for tree view/navigation

Returns

NoteSummary[]

Implementation of

IUserNoteRepository.getAllNoteSummaries


getById()

getById(id): UserNote | undefined

Defined in: Data/Repositories/UserNoteRepository.ts:109

Get a note by ID, including its linked verses and child notes.

Parameters

id

number

The note_id to look up

Returns

UserNote | undefined

The note with linked verses and children loaded, or undefined if not found

Implementation of

IUserNoteRepository.getById


getByTag()

getByTag(tag): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:244

Get notes by tag

Parameters

tag

string

Returns

UserNote[]

Implementation of

IUserNoteRepository.getByTag


getByType()

getByType(noteType): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:140

Get notes by type

Parameters

noteType

"verse_note" | "document" | "sermon" | "study" | "journal" | "prayer"

Returns

UserNote[]

Implementation of

IUserNoteRepository.getByType


getChildNotes()

getChildNotes(parentNoteId): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:214

Get child notes for a parent note

Parameters

parentNoteId

number

Returns

UserNote[]

Implementation of

IUserNoteRepository.getChildNotes


getForVerse()

getForVerse(verseId): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:167

Get all notes that cover a specific verse. Matches notes where verseIdStart <= verseId <= verseIdEnd (range-aware).

Parameters

verseId

number

The calculated verse ID to find notes for

Returns

UserNote[]

Array of notes ordered by most recently modified first

Implementation of

IUserNoteRepository.getForVerse


getForVerseRange()

getForVerseRange(startVerseId, endVerseId): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:188

Get all notes that overlap with a verse range. Uses range-overlap logic: a note matches if its verse range intersects with the query range (not just containment).

Parameters

startVerseId

number

Start of the query range (inclusive)

endVerseId

number

End of the query range (inclusive)

Returns

UserNote[]

Array of notes ordered by starting verse, then most recently modified

Implementation of

IUserNoteRepository.getForVerseRange


getModifiedSince()

getModifiedSince(since, limit?): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:253

Parameters

since

string

limit?

number

Returns

UserNote[]

Implementation of

IUserNoteRepository.getModifiedSince


getNextVerseWithContent()

getNextVerseWithContent(currentVerseId): number | undefined

Defined in: Data/Repositories/UserNoteRepository.ts:275

Get the next verse ID that has a note

Parameters

currentVerseId

number

Returns

number | undefined

Implementation of

IUserNoteRepository.getNextVerseWithContent


getPreviousVerseWithContent()

getPreviousVerseWithContent(currentVerseId): number | undefined

Defined in: Data/Repositories/UserNoteRepository.ts:290

Get the previous verse ID that has a note

Parameters

currentVerseId

number

Returns

number | undefined

Implementation of

IUserNoteRepository.getPreviousVerseWithContent


getTopLevelNotes()

getTopLevelNotes(): UserNote[]

Defined in: Data/Repositories/UserNoteRepository.ts:203

Get top-level notes (no parent)

Returns

UserNote[]

Implementation of

IUserNoteRepository.getTopLevelNotes


getVersesWithNotesInRange()

getVersesWithNotesInRange(startVerseId, endVerseId): number[]

Defined in: Data/Repositories/UserNoteRepository.ts:333

Get verse IDs that have non-empty notes within a range. Used for displaying note indicator icons in the Bible text view.

Filters out whitespace-only notes (e.g., empty HTML like <p></p>) by stripping HTML tags and checking for remaining non-whitespace content.

Parameters

startVerseId

number

Start of the verse range (inclusive)

endVerseId

number

End of the verse range (inclusive)

Returns

number[]

Sorted array of verse IDs that have substantive notes

Implementation of

IUserNoteRepository.getVersesWithNotesInRange


search(query): UserNote[]

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

Full-text search across note content using SQLite FTS5.

Parameters

query

string

FTS5 query string (supports AND, OR, NOT, quoted phrases)

Returns

UserNote[]

Array of matching notes ordered by most recently modified first

Implementation of

IUserNoteRepository.search


update()

update(entity): UserNote

Defined in: Data/Repositories/UserNoteRepository.ts:418

Update an existing note in the database. Automatically updates the modified_date via UserNote.touch. Replaces all linked verses (deletes existing, inserts current).

Parameters

entity

UserNote

The UserNote to update (must have noteId set)

Returns

UserNote

The updated entity

Throws

Error if entity.noteId is not set

Implementation of

IUserNoteRepository.update