mirror of
https://github.com/lifegpc/bookdownload.git
synced 2026-07-08 01:31:31 +08:00
Add support to save chapter to databases
This commit is contained in:
21
src/db/interfaces.ts
Normal file
21
src/db/interfaces.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { DbConfig, DbType } from "../config";
|
||||
import { IndexedDb } from "./indexedDb";
|
||||
import type { QdChapterInfo } from "../types";
|
||||
|
||||
export interface Db {
|
||||
init(): Promise<void>;
|
||||
saveQdChapter(info: QdChapterInfo): Promise<void>;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
export async function createDb(): Promise<Db> {
|
||||
const config = new DbConfig();
|
||||
await config.init();
|
||||
switch (config.DbType) {
|
||||
case DbType.IndexedDb:
|
||||
const db = new IndexedDb(config.IndexedDb);
|
||||
return db;
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user