Tankōbon / main/db/library-repository / LibraryRepository
Class: LibraryRepository
Defined in: main/db/library-repository.ts:98
Persists the comic library (one row per known file) to the local database, as the active user sees it.
Constructors
Constructor
new LibraryRepository(
db,userId?,paths?):LibraryRepository
Defined in: main/db/library-repository.ts:107
userId says whose rating, tags and progress the reads and writes are about (the active user, in the app); the books and their metadata are the library's, common to everyone. paths converts between the paths the database stores (relative to a library folder, see PathRoots) and the absolute ones everything else works with: no method takes or returns a stored path.
Parameters
db
DatabaseSync
userId?
() => string
paths?
PathCodec = IDENTITY_PATHS
Returns
LibraryRepository
Methods
adoptRoots()
adoptRoots():
number
Defined in: main/db/library-repository.ts:211
Stores the entries whose file is inside a library folder relative to it, after a folder was added or found again on this machine (the paths of a database from before the roots, or of books added on their own, are absolute). Nothing moves on disk. Returns how many entries changed.
Returns
number
clear()
clear():
number
Defined in: main/db/library-repository.ts:505
Empties the library: every entry, its credits and its place in the reading lists, plus the people (who only exist through credits). The files on disk are left untouched. Returns the number of entries removed.
Returns
number
get()
get(
id):LibraryEntry|null
Defined in: main/db/library-repository.ts:148
One entry by id, or null if it isn't (or no longer) in the library.
Parameters
id
string
Returns
LibraryEntry | null
hasPath()
hasPath(
filePath):boolean
Defined in: main/db/library-repository.ts:202
Whether a file is already in the library, so a folder scan can skip it without opening it.
Parameters
filePath
string
Returns
boolean
idOfPath()
idOfPath(
filePath):string|null
Defined in: main/db/library-repository.ts:229
Id of the entry whose file is filePath, or null when that file isn't in the library.
Parameters
filePath
string
Returns
string | null
lastOpenedPath()
lastOpenedPath():
string|null
Defined in: main/db/library-repository.ts:367
Path of the most recently opened comic, if any. Used to reopen the file dialog in the directory the user last picked a book from, rather than the OS default.
Returns
string | null
list()
list():
LibraryEntry[]
Defined in: main/db/library-repository.ts:131
Every entry, most recently opened first.
Returns
register()
register(
filePath,title,pageCount,fileCount,fileSize):"created"|"existing"
Defined in: main/db/library-repository.ts:250
Adds a comic discovered by a folder scan. Unlike touch, an entry that already exists is left completely alone — a scan is not a read, so it must not bump last_opened_at or refresh metadata behind the user's back. New rows get last_opened_at = added_at, which is what puts a freshly scanned batch at the top of the library list.
Parameters
filePath
string
title
string
pageCount
number
fileCount
number
fileSize
number
Returns
"created" | "existing"
remove()
remove(
id):void
Defined in: main/db/library-repository.ts:491
Removes the entry (its credits, and its place in the reading lists) from the library; the file on disk is left untouched.
Parameters
id
string
Returns
void
touch()
touch(
filePath,title,pageCount,fileCount,fileSize):LibraryEntry
Defined in: main/db/library-repository.ts:165
Registers a comic as just opened: creates it on first open, else refreshes its metadata. Never touches rating/tags nor the looked-up metadata (series, credits…), which are only ever set by the user, and keeps a locked title instead of the file-name-derived title.
Parameters
filePath
string
title
string
pageCount
number
fileCount
number
fileSize
number
Returns
unmeasured()
unmeasured():
object[]
Defined in: main/db/library-repository.ts:411
The entries the background scan has yet to measure (id and path), most recently opened first.
Returns
object[]
updateImageStats()
updateImageStats(
id,width,height):LibraryEntry|null
Defined in: main/db/library-repository.ts:405
Stores the average page size measured by the background scan; returns the updated entry, or null if the id is unknown.
Parameters
id
string
width
number
height
number
Returns
LibraryEntry | null
updateMetadata()
updateMetadata(
id,update):LibraryEntry|null
Defined in: main/db/library-repository.ts:438
Writes the metadata fields present in update (typically the ones the user accepted from a lookup) and leaves the others alone. A new title is locked, so reopening the file doesn't put the file name back. Returns the updated entry, or null if the id is unknown.
Parameters
id
string
update
Returns
LibraryEntry | null
updatePath()
updatePath(
id,filePath):boolean
Defined in: main/db/library-repository.ts:239
Points an entry at its file's new location, after the library organization moved it; everything else (progress, rating, tags, metadata, reading-list places) stays. Returns false when the entry is gone or another entry already has that path (paths are unique).
Parameters
id
string
filePath
string
Returns
boolean
updateProgress()
updateProgress(
id,currentPage):void
Defined in: main/db/library-repository.ts:378
Saves the last page read (0-based) for resuming later. Reaching the last page also records the book's first completion date (finished_at), for the reading statistics.
Parameters
id
string
currentPage
number
Returns
void
updateRating()
updateRating(
id,rating):void
Defined in: main/db/library-repository.ts:399
Sets the user rating: 0 (unrated) to 5. The value is stored as given, not clamped.
Parameters
id
string
rating
number
Returns
void
updateTags()
updateTags(
id,tags):void
Defined in: main/db/library-repository.ts:419
Replaces the entry's tags. Tagging a book Lu also records its first completion date, like reaching its last page.
Parameters
id
string
tags
string[]
Returns
void
upsert()
upsert(
entry):"created"|"updated"
Defined in: main/db/library-repository.ts:277
Writes a whole entry, matching an existing one by its file path (paths are unique, ids are not stable across machines) — used by the JSON import to restore a snapshot on top of the current library. Unlike touch, this does overwrite rating/tags and the looked-up metadata, credits included: they're part of what the user is restoring.
Parameters
entry
Returns
"created" | "updated"