| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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", 2, {
- upgrade(db, oldVersion, newVersion) {
- console.log(oldVersion, newVersion);
- if (oldVersion === 0) {
- 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,
- });
- } else if (oldVersion === 1) {
- const historyStore = db.transaction("history", "versionchange");
- const store = historyStore.store;
- store.deleteIndex("historyIsFavorite");
- store.createIndex("historyIsFavorite", "isFavorite", {
- unique: false,
- });
- }
- },
- });
- }
|