Skip to content

Skeudenn / main/db/import-service / applyImport

Function: applyImport() ​

applyImport(db, libraryRepo, settingsRepo, readingListRepo, data): object

Defined in: src/main/db/import-service.ts:191

Merges a parsed snapshot into the local database: library entries are matched by file path (the snapshot wins for the ones it contains, so restoring a backup restores its progress, ratings and tags), entries only present locally are left alone, and settings are replaced (except the ones only the main process writes, MAIN_PROCESS_SETTINGS, which keep their local value). Reading lists are matched by id, the snapshot winning too (their order included: the snapshot's lists come first, in its order); their books are found by path, and a path that matches no library entry is dropped.

All or nothing: the whole merge runs in one transaction, so an error midway leaves the database as it was, and 2 000 books take a fraction of the time of one commit per statement. db must be the database the three repositories were built on.

Parameters ​

db ​

DatabaseSync

libraryRepo ​

LibraryRepository

settingsRepo ​

SettingsRepository

readingListRepo ​

ReadingListRepository

data ​

ExportedData

Returns ​

object

added ​

added: number

updated ​

updated: number