You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -107,16 +107,18 @@ IndexedDB uses the [standard serialization algorithm](https://www.w3.org/TR/html
107
107
108
108
An example of object that can't be stored: an object with circular references. Such objects are not serializable. `JSON.stringify` also fails for such objects.
109
109
110
-
**There must be an unique `key` for every value in the store.**
110
+
**There must be a unique `key` for every value in the store.**
111
111
112
112
A key must have a type one of: number, date, string, binary, or array. It's an unique identifier: we can search/remove/update values by the key.
113
113
114
114

115
115
116
-
As we'll see very soon, we can provide a key when we add an value to the store, similar to `localStorage`. But when we store objects, IndexedDB allows to setup an object property as the key, that's much more convenient. Or we can auto-generate keys.
116
+
117
+
As we'll see very soon, we can provide a key when we add a value to the store, similar to `localStorage`. But when we store objects, IndexedDB allows to setup an object property as the key, that's much more convenient. Or we can auto-generate keys.
-`readwrite` -- can only read and write the data, but not create/remove/alter object stores.
196
198
197
-
There'is also `versionchange` transaction type: such transactions can do everything, but we can't create them manually. IndexedDB automatically creates a `versionchange` transaction when opening the database, for `updateneeded` handler. That's why it's a single place where we can update the database structure, create/remove object stores.
199
+
There's also `versionchange` transaction type: such transactions can do everything, but we can't create them manually. IndexedDB automatically creates a `versionchange` transaction when opening the database, for `updateneeded` handler. That's why it's a single place where we can update the database structure, create/remove object stores.
198
200
199
201
```smart header="Why there exist different types of transactions?"
200
202
Performance is the reason why transactions need to be labeled either `readonly` and `readwrite`.
-**`keyPath`** -- path to the object field that the index should track (we're going to search by that field),
463
465
-**`option`** -- an optional object with properties:
464
466
-**`unique`** -- if true, then there may be only one object in the store with the given value at the `keyPath`. The index will enforce that by generating an error if we try to add a duplicate.
465
-
-**`multiEntry`** -- only used if there value on `keyPath` is an array. In that case, by default, the index will treat the whole array as the key. But if `multiEntry` is true, then the index will keep a list of store objects for each value in that array. So array members become index keys.
467
+
-**`multiEntry`** -- only used if the value on `keyPath` is an array. In that case, by default, the index will treat the whole array as the key. But if `multiEntry` is true, then the index will keep a list of store objects for each value in that array. So array members become index keys.
466
468
467
469
In our example, we store books keyed by `id`.
468
470
@@ -611,7 +613,7 @@ Whether there are more values matching the cursor or not -- `onsuccess` gets cal
611
613
612
614
In the example above the cursor was made for the object store.
613
615
614
-
But we also can make a cursor over an index. As we remember, indexes allow to search by an object field. Cursors over indexes to precisely the same as over object stores -- they save memory by returning one value at a timee.
616
+
But we also can make a cursor over an index. As we remember, indexes allow to search by an object field. Cursors over indexes to precisely the same as over object stores -- they save memory by returning one value at a time.
615
617
616
618
For cursors over indexes, `cursor.key` is the index key (e.g. price), and we should use `cursor.primaryKey` property the object key:
A we know already, a transaction auto-commits as soon as the browser is done with the current code and microtasks. So if we put an *macrotask* like `fetch` in the middle of a transaction, then the transaction won't wait for it to finish. It just auto-commits. So the next request in it would fail.
690
+
691
+
As we already know, a transaction auto-commits as soon as the browser is done with the current code and microtasks. So if we put a *macrotask* like `fetch` in the middle of a transaction, then the transaction won't wait for it to finish. It just auto-commits. So the next request in it would fail.
692
+
689
693
690
694
For a promise wrapper and `async/await` the situation is the same.
691
695
@@ -712,7 +716,7 @@ The workaround is same as when working with native IndexedDB: either make a new
712
716
713
717
Internally, the wrapper performs a native IndexedDB request, adding `onerror/onsuccess` to it, and returns a promise that rejects/resolves with the result.
714
718
715
-
That works most fine of the time. The examples are at the lib page <https://github.com/jakearchibald/idb>.
719
+
That works fine most of the time. The examples are at the lib page <https://github.com/jakearchibald/idb>.
716
720
717
721
In few rare cases, when we need the original `request` object, we can access it as `promise.request` property of the promise:
0 commit comments