Dexie<\/a>\u306fIndexedDB\u5229\u7528\u3092\u975e\u5e38\u306b\u697d\u306b\u3057\u3066\u304f\u308c\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u81ea\u5206\u3068\u3057\u3066\u306f\u3001IndexedDB\u306e\u30ec\u30b3\u30fc\u30c9\u3092Typescript\u306e\u30af\u30e9\u30b9\u306bO\/R Mapping\u3057\u3066\u304f\u308c\u308b\u70b9\u304c\u975e\u5e38\u306b\u3042\u308a\u304c\u305f\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
npm\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n
npm install dexie<\/code><\/pre>\nDB\u5b9a\u7fa9\u304a\u3088\u3073\u30b9\u30bf\u30fc\u30c8<\/h3>\n
dexie.ts<\/code>\u3092\u4f5c\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067DB\u5b9a\u7fa9\u304a\u3088\u3073\u30b9\u30bf\u30fc\u30c8\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\nimport Dexie from 'dexie'\n\n\/\/ \u30b9\u30ad\u30fc\u30de\u306e\u4fee\u6b63\u304c\u3042\u308b\u5834\u5408\u3001\u3053\u306e\u5024\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u3042\u308a\nconst SCHEMA_VERSION = 1\n\n\/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30c8\u30a2\u306b\u5bfe\u5fdc\u3059\u308b\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3002interface\u3067\u3082OK\u3002\u5b9f\u969b\u306b\u306fmodel\u306f\u5225\u30d5\u30a1\u30a4\u30eb\u306b\u5b9a\u7fa9\u3057\u3066\u3042\u308a\u307e\u3059\nexport class AccessCountModel {\n key: number\n readCount: number\n updateCount: number\n deleteCount: number\n constructor(key: number, readCount = 0, updateCount = 0, deleteCount = 0) {\n this.key = key\n this.readCount = readCount\n this.updateCount = updateCount\n this.deleteCount = deleteCount\n }\n}\ninterface HogeDatabase extends Dexie {\n accessCounts: Dexie.Table<AccessCountModel, number> \/\/ \u3053\u3053\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30c8\u30a2\u3068\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u3092\u5bfe\u5fdc\u3065\u3051\u3066\u3044\u308b\u3002number\u306f\u30ad\u30fc\u306e\u578b\n}\n\nconst dexieDb = new Dexie('hoge-database') as HogeDatabase\ndexieDb.version(SCHEMA_VERSION).stores({\n accessCounts: 'key,readCount,updateCount,deleteCount', \/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30c8\u30a2\u306e\u5b9a\u7fa9\n})\nexport default dexieDb<\/code><\/pre>\nrepository\u30af\u30e9\u30b9\u306e\u4f5c\u6210<\/h3>\n
\u76f4\u63a5\u3001dexieDb\u3092\u4f7f\u3063\u3066\u3082\u3044\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u6bce\u56dethen<\/code>\u3084catch<\/code>\u3092\u66f8\u304f\u306e\u3082\u5927\u5909\u306a\u306e\u3067\u3001repository\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\nimport dexieDb, { AccessCountModel } from '.\/dexie'\n\nexport class AccessCountRepository {\n \/\/ \u30c7\u30fc\u30bf\u53d6\u5f97\n async get(key: number): Promise<AccessCountModel | undefined> {\n return dexieDb.accessCounts\n .get(key)\n .then(async (count: AccessCountModel | undefined) => {\n return count\n })\n .catch((error) => {\n throw new Error(`Error getting access count:, ${error}`)\n })\n }\n\n \/\/ \u30c7\u30fc\u30bf\u66f4\u65b0\n async save(accessCount: AccessCountModel): Promise<AccessCountModel> {\n await dexieDb.accessCounts.update(accessCount.key, accessCount)\n return await this.get(accessCount.key)\n }\n}<\/code><\/pre>\n\u5229\u7528<\/h3>\n
\u5b9f\u969b\u306e\u5229\u7528\u7b87\u6240\u3067\u306f\u3001repository\u30af\u30e9\u30b9\u3092import\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n
import { AccessCountRepository } '.\/repositories'\nimport { AccessCountModel } from '.\/dexie'\n\nclass Hoge {\n accessCountRepository = new AccessCountRepository()\n async fuga(): Promise<void> {\n const key = 3600\n const accessCount: AccessCountModel = await this.accessCountRepository.get(key)\n console.log(accessCount)\n }\n}<\/code><\/pre>\nCDN\u5229\u7528<\/h2>\n
dexie\u306fCDN\u3082\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u3061\u3089\u3092\u4f7f\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\nhtml\u3067dexie.min.js<\/code>\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001<\/p>\n<body>\n <script src="https:\/\/unpkg.com\/dexie@latest\/dist\/dexie.min.js"><\/script>\n<\/body><\/code><\/pre>\nwebpack.config.js\u306eexternals\u306bdexie<\/code>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002global\u5909\u6570\u540d\u306fDexie<\/code>\u306a\u306e\u3067\u305d\u308c\u3092\u6307\u5b9a\u3057\u3066\u307e\u3059\u3002<\/p>\n externals: {\n dexie: 'Dexie',\n }<\/code><\/pre>\n\u3053\u308c\u3067\u3001\u30d0\u30f3\u30c9\u30eb\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306f\u9664\u5916\u3055\u308c\u3001CDN\u304b\u3089\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n
\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/h2>\n\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30c8\u30a2\u304c\u5b58\u5728\u3057\u306a\u3044<\/h3>\n
\u5b58\u5728\u3057\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30b9\u30c8\u30a2\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n
\nNotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.<\/p>\n<\/blockquote>\n
\u3053\u306e\u3088\u3046\u306a\u5834\u5408\u3001\u81ea\u5206\u306e\u7d4c\u9a13\u7684\u306b\u306f\u539f\u56e0\u306f\u4ee5\u4e0b\u306e\u4e8c\u3064\u306e\u3069\u3061\u3089\u304b\u3067\u3057\u305f\u3002<\/p>\n
\n- DB\u5b9a\u7fa9\u304c\u9593\u9055\u3063\u3066\u3044\u308b\uff08typo\u3084\u5b9a\u7fa9\u3057\u5fd8\u308c\uff09<\/li>\n
- DB\u5b9a\u7fa9\u3092\u5909\u66f4\u3057\u305f\u306e\u306b\u3001\u30b9\u30ad\u30fc\u30de\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u5909\u66f4\u3057\u308f\u3059\u308c\u3066\u3044\u308b<\/li>\n<\/ul>\n
\u6700\u5f8c\u306b<\/h2>\n
\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u304b\u3068\u601d\u3046\u3050\u3089\u3044\u304b\u3063\u3061\u308a\u3057\u305f\u611f\u3058\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002
\n\u305f\u3060\u3001\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u5185\u5bb9\u306f\u3001\u500b\u3005\u306e\u30af\u30a8\u30ea\u304c\u500b\u5225\u306etransaction\u3067\u5b9f\u884c\u3055\u308c\u308b\u72b6\u614b\u306a\u306e\u3067\u3001\u4e00\u9023\u306e\u51e6\u7406\u3092\u4e00\u3064\u306etransaction\u5185\u3067\u5b9f\u884c\u3059\u308b\u5834\u5408\u306f\u3082\u3046\u5c11\u3057\u5de5\u592b\u304c\u5fc5\u8981\u305d\u3046\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u30d6\u30e9\u30a6\u30b6\u3067\u30c7\u30fc\u30bf\u3092\u4fdd\u7ba1\u3059\u308b\u5834\u5408\u3001Web Storage\uff08sessionStorage\u3084localStorage \uff09\u3092\u4f7f\u3046\u3053\u3068\u304c\u591a\u304b\u3063\u305f\u3068\u601d\u3044\u307e\u3059\u304c\u3001IndexedDB\u304c\u767b\u5834\u3057\u305f\u3053\u3068\u3067\u3042\u3048\u3066Web Storage\u3092\u4f7f\u3046\u7406\u7531\u304c\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002 IndexedDB\u3092\u4f7f\u3046\u5834\u5408\u3001Dexie.js\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3060\u3044\u3076\u5b9f\u88c5\u304c\u30b9\u30c3\u30ad\u30ea\u3059\u308b\u306e\u3067\u3001\u4f7f\u3044\u65b9\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 Web Storage\u3068IndexedDB\u306e\u9055\u3044 \u305d\u3082\u305d\u3082\u672c\u5f53\u306bIndexedDB\u3092\u4f7f\u3046\u306e\u304c\u826f\u3044\u306e\u304b\u3001\u3068\u3044\u3046\u7591\u554f\u304c\u3042\u308b\u306e\u3067\u5ff5\u306e\u305f\u3081\u3001Web Storage\u3068 IndexedDB\u306e\u9055\u3044\u3092\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\u8abf\u3079\u305f\u5168\u3066\u306e\u70b9\u3067IndexedDB\u306e\u65b9\u304c\u826f\u3044\u306e\u3067\u3001\u3084\u306f\u308aIndexedDB\u4e00\u629e\u3067\u3059\u306d\u3002 \u9805\u76ee Web Storage IndexedDB \u578b \u6587\u5b57\u5217\u306e\u307f boolean\u3001\u6570\u5024\u3001\u6587\u5b57\u5217\u3001date\u306a\u3069\u8272\u3005 RDB\u306e\u30c6\u30fc\u30d6\u30eb \u306a\u3057\u3002key-v <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,25],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/242"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":243,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/242\/revisions\/243"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}