| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { openDB, DBSchema, StoreNames } from "idb";
- export interface NovelDb extends DBSchema {
- history: {
- value: HistoryItem;
- key: string;
- indexes: {
- uri: string;
- historyUpdateTime: Date;
- historyIsReading: number;
- historyIsFavorite: number;
- };
- };
- }
- export default function getDb() {
- return openDB<NovelDb>("NovelDit", 3, {
- upgrade(db, oldVersion, newVersion) {
- console.log(db, oldVersion, newVersion);
- if (oldVersion && newVersion && newVersion > oldVersion) {
- db.deleteObjectStore("history");
- }
- const historyStore = db.createObjectStore("history", {
- keyPath: "uri",
- });
- historyStore.createIndex("historyUpdateTime", "readTime", {
- unique: false,
- });
- historyStore.createIndex("historyIsReading", ["isReading", "readTime"], {
- unique: false,
- });
- historyStore.createIndex("historyIsFavorite", "isFavorite", {
- unique: false,
- });
- },
- });
- }
|