From 53a3ccdab20de8cc1e939308c69e7598ca4f48ed Mon Sep 17 00:00:00 2001 From: redhoodsu Date: Sun, 6 Oct 2024 23:36:50 +0800 Subject: [PATCH] chore: small changes --- devtools/db.js | 32 ++++++++++++++++++++++++++++++++ devtools/target.html | 40 +++++----------------------------------- devtools/target.js | 2 ++ src/lib/resources.ts | 23 +++++++++++++++++++---- 4 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 devtools/db.js diff --git a/devtools/db.js b/devtools/db.js new file mode 100644 index 0000000..87432b5 --- /dev/null +++ b/devtools/db.js @@ -0,0 +1,32 @@ +// https://gist.github.com/enjalot/6472041 +var indexedDB = window.indexedDB +var open = indexedDB.open('MyDatabase', 1) +open.onupgradeneeded = function () { + var db = open.result + var store = db.createObjectStore('MyObjectStore', { keyPath: 'id' }) + var index = store.createIndex('NameIndex', ['name.last', 'name.first']) +} +open.onsuccess = function () { + var db = open.result + var tx = db.transaction('MyObjectStore', 'readwrite') + var store = tx.objectStore('MyObjectStore') + var index = store.index('NameIndex') + + store.put({ id: 12345, name: { first: 'John', last: 'Doe' }, age: 42 }) + store.put({ id: 67890, name: { first: 'Bob', last: 'Smith' }, age: 35 }) + + var getJohn = store.get(12345) + var getBob = index.get(['Smith', 'Bob']) + + getJohn.onsuccess = function () { + console.log(getJohn.result.name.first) // => "John" + } + + getBob.onsuccess = function () { + console.log(getBob.result.name.first) // => "Bob" + } + + tx.oncomplete = function () { + db.close() + } +} diff --git a/devtools/target.html b/devtools/target.html index 49704e4..1b35984 100644 --- a/devtools/target.html +++ b/devtools/target.html @@ -4,6 +4,7 @@ + Target