@@ -9,10 +9,16 @@ import { libraryItems, mangaProgress, bookProgress, mangaBookmarks, bookBookmark
99import { HistoryItem , Manga_BookItem } from "@common/types/legacy" ;
1010import Database from "better-sqlite3" ;
1111import { dateFromOldDateString , electronOnly , log } from "../util" ;
12- import { AddToLibraryData , UpdateBookProgressData , UpdateMangaProgressData } from "@common/types/db" ;
12+ import {
13+ AddToLibraryData ,
14+ BookProgress ,
15+ LibraryItem ,
16+ MangaProgress ,
17+ UpdateBookProgressData ,
18+ UpdateMangaProgressData ,
19+ } from "@common/types/db" ;
1320
1421electronOnly ( ) ;
15- // todo : add proper error handling
1622
1723export const DB_PATH = app . isPackaged ? path . join ( app . getPath ( "userData" ) , "data.db" ) : "data.db" ;
1824
@@ -23,17 +29,17 @@ export class DatabaseService {
2329 this . _db = drizzle ( { client : sqlite , schema } ) ;
2430 }
2531
26- get db ( ) {
32+ get db ( ) : ReturnType < typeof drizzle > {
2733 return this . _db ;
2834 }
29- async initialize ( ) {
35+ async initialize ( ) : Promise < void > {
3036 console . log ( "Migrating database" ) ;
31- migrate ( this . _db , {
37+ await migrate ( this . _db , {
3238 migrationsFolder : app . isPackaged ? path . join ( path . dirname ( app . getAppPath ( ) ) , "drizzle" ) : "drizzle" ,
3339 } ) ;
3440 console . log ( this . _db . all ( `select unixepoch() as time` ) ) ;
3541 }
36- async addLibraryItem ( data : AddToLibraryData ) {
42+ async addLibraryItem ( data : AddToLibraryData ) : Promise < LibraryItem > {
3743 return await this . _db . transaction ( async ( tx ) => {
3844 const [ item ] = await tx . insert ( libraryItems ) . values ( data . data ) . returning ( ) ;
3945 if ( data . type === "manga" ) {
@@ -54,7 +60,7 @@ export class DatabaseService {
5460 } ) ;
5561 }
5662
57- async updateMangaProgress ( data : UpdateMangaProgressData ) {
63+ async updateMangaProgress ( data : UpdateMangaProgressData ) : Promise < MangaProgress [ ] > {
5864 const { itemLink, ...updateData } = data ;
5965 return await this . _db
6066 . update ( mangaProgress )
@@ -66,7 +72,7 @@ export class DatabaseService {
6672 . returning ( ) ;
6773 }
6874
69- async updateMangaChapterRead ( itemLink : string , chapterNames : string [ ] , read : boolean ) {
75+ async updateMangaChapterRead ( itemLink : string , chapterNames : string [ ] , read : boolean ) : Promise < string [ ] > {
7076 return await this . _db . transaction ( async ( tx ) => {
7177 const [ progress ] = await tx . select ( ) . from ( mangaProgress ) . where ( eq ( mangaProgress . itemLink , itemLink ) ) ;
7278 if ( ! progress ) {
@@ -89,7 +95,7 @@ export class DatabaseService {
8995 } ) ;
9096 }
9197
92- async updateBookProgress ( data : UpdateBookProgressData ) {
98+ async updateBookProgress ( data : UpdateBookProgressData ) : Promise < BookProgress [ ] > {
9399 const { itemLink, ...updateData } = data ;
94100 return await this . _db
95101 . update ( bookProgress )
@@ -101,9 +107,7 @@ export class DatabaseService {
101107 . returning ( ) ;
102108 }
103109
104- // todo: review
105- // todo: add option in frontend to manually import as well
106- async migrateFromJSON ( historyData : HistoryItem [ ] , bookmarkData : Manga_BookItem [ ] ) {
110+ async migrateFromJSON ( historyData : HistoryItem [ ] , bookmarkData : Manga_BookItem [ ] ) : Promise < void > {
107111 log . log (
108112 "Migrating from JSON " +
109113 historyData . length +
0 commit comments