license import { openDB } from 'idb' ; import BooksDb from './versions/books-db' ; import upgradeBooksDbFromV2 from './versions/v2/upgrade' ; export function createBooksDb ( name = 'books' ) { return openDB < BooksDb > ( name , 3 , { async upgrade ( oldDb , oldVersion , newVersion , transaction ) { switch ( oldVersion ) { case 0 : { const dataStore = oldDb . createObjectStore ( 'data' , { keyPath : 'id' , autoIncrement : true , } ) ; dataStore . createIndex ( 'title' , 'title' ) ; oldDb . createObjectStore ( 'bookmark' , { keyPath : 'dataId' , } ) ; oldDb . createObjectStore ( 'lastItem' ) ; break ; } case 2 : { await upgradeBooksDbFromV2 ( oldDb , oldVersion , newVersion , transaction ) ; break ; } } } , } ) ; }