diff --git a/client/src/core/repository/repository.indexedDB.ts b/client/src/core/repository/repository.indexedDB.ts new file mode 100644 index 0000000..7797d46 --- /dev/null +++ b/client/src/core/repository/repository.indexedDB.ts @@ -0,0 +1,20 @@ +import { PlainTodo, InputTodo } from '@todo/todo.type'; +import { ITodoListDataBase } from '@repository/repository.interface'; +import { IDBPDatabase, openDB } from 'idb'; + +const DB_NAME = 'OaO'; +const TABLE_NAME = 'todos'; + +export class IndexedDBFactory { + async createDB(): Promise { + const db: IDBPDatabase = await openDB(DB_NAME, 1, { + upgrade(db: IDBPDatabase) { + if (!db.objectStoreNames.contains(TABLE_NAME)) db.createObjectStore(TABLE_NAME); + }, + }); + + return new IndexedDB(db); + } +} + +export class IndexedDB implements ITodoListDataBase {