From d747720dc79bebef6a062165002811020905e6af Mon Sep 17 00:00:00 2001 From: daeseong9388 Date: Tue, 29 Nov 2022 23:14:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20IndexedDB=20=EB=AA=A8=EB=93=88=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20Factory=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/repository/repository.indexedDB.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 client/src/core/repository/repository.indexedDB.ts 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 {