Skip to content

Commit 3d0ab52

Browse files
git squash commit for putall.
f11de4f git squash commit for putall. 4c8f697698a7ad567bdcc3075f34a76cbd03e723 git squash commit for putall. 5cc88a474a7ebae8fe3b505ffa4cad184988fbdd git squash commit for putall. 008747487723e239b1badd7b2324cdf76ae95715 git squash commit for putall. 2bfcd08e6dcd6b68ab3135375c66f99ec45cfe34 git squash commit for putall. 5e447cac9eb4b2bd35a425e2ece7779a0ec6cb24 Initial algorithms for putAll bb5627af9ec7f1e5819ae25ab7b6b9f7808c8fc4 Sketch out putAllXXX methods e46dcd058e677f3bf7957938961670d54a65db81 rebased 69edb5b8a07b6cbce22d012fe0a9a9427a9f0553 rebase cleanup - still a weird idl ref error 5c8240291c541df290e3fe9feec9a1e073b845ee disambiguate link a201dcd56f706a91db57f589b6184d112411515a bangbang 58bd52cf997d061aa8cbe344b0baea713a2ae860 fix TypeError link
1 parent bfd4953 commit 3d0ab52

File tree

1 file changed

+160
-3
lines changed

1 file changed

+160
-3
lines changed

index.bs

Lines changed: 160 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,8 @@ interface IDBObjectStore {
27112711
readonly attribute boolean autoIncrement;
27122712

27132713
[NewObject] IDBRequest put(any value, optional any key);
2714+
[NewObject] IDBRequest putAllValues(sequence<any> values);
2715+
[NewObject] IDBRequest putAllEntries(sequence<sequence<any>> entries);
27142716
[NewObject] IDBRequest add(any value, optional any key);
27152717
[NewObject] IDBRequest delete(any query);
27162718
[NewObject] IDBRequest clear();
@@ -2888,6 +2890,27 @@ and false otherwise.
28882890
If successful, |request|'s {{IDBRequest/result}} will be the
28892891
[=object-store/record=]'s [=/key=].
28902892

2893+
: |request| = |store| . {{IDBObjectStore/putAllValues()|putAllValues}}(|values|)
2894+
2895+
::
2896+
Adds or updates multiple [=object-store/records=] in |store| with the given array of |values|.
2897+
2898+
[=/Keys=] can not be explicitly specified using this method, so it can only be used with an [=/object store=] that either has a [=/key generator=] or that uses [=object-store/in-line keys=]. Otherwise, a "{{DataError}}" {{DOMException}} will be thrown.
2899+
2900+
2901+
If any [=/record=] fails to be stored, no updates will be made and the |request| will fail, with |request|'s {{IDBRequest/error!!attribute}} set to an error e.g. a "{{ConstraintError}}" {{DOMException}}.
2902+
2903+
2904+
: |request| = |store| . {{IDBObjectStore/putAllEntries()|putAllEntries}}(|entries|)
2905+
2906+
::
2907+
Adds or updates multiple [=object-store/records=] in |store| with the given array of |entries|. Each entry is a two element array with a [=/key=] and [=/value=] for the record.
2908+
2909+
This method can only be used with an [=/object store=] that uses [=object-store/out-of-line keys=]. Otherwise, a "{{DataError}}" {{DOMException}} will be thrown.
2910+
2911+
If any [=/record=] fails to be stored, no updates will be made and the |request| will fail, with |request|'s {{IDBRequest/error!!attribute}} set to an error e.g. a "{{ConstraintError}}" {{DOMException}}.
2912+
2913+
28912914
: |request| = |store| .
28922915
{{IDBObjectStore/delete()|delete}}(|query|)
28932916
::
@@ -2906,13 +2929,13 @@ and false otherwise.
29062929
</div>
29072930

29082931

2909-
The <dfn method for=IDBObjectStore>put(|value|, |key|)</dfn> method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| false.
2932+
The <dfn method for=IDBObjectStore>put(|value|, |key|)</dfn> method steps are to return the result of running [=add or put a single record=] with [=/this=], |value|, |key| and false.
29102933

2911-
The <dfn method for=IDBObjectStore>add(|value|, |key|)</dfn> method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| true.
2934+
The <dfn method for=IDBObjectStore>add(|value|, |key|)</dfn> method steps are to return the result of running [=add or put a single record=] with [=/this=], |value|, |key| and true.
29122935

29132936
<div algorithm>
29142937

2915-
To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps:
2938+
To <dfn>add or put a single record</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps:
29162939

29172940
1. Let |transaction| be |handle|'s
29182941
[=object-store-handle/transaction=].
@@ -2983,6 +3006,119 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,
29833006

29843007
1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.
29853008

3009+
</div>
3010+
3011+
The <dfn method for=IDBObjectStore>putAllValues(|values|)</dfn> method steps are to return the result of running [=add or put multiple records=] with [=/this=], |values|, and false.
3012+
3013+
<div algorithm>
3014+
3015+
The <dfn method for=IDBObjectStore>putAllEntries(|entries|)</dfn> method steps are:
3016+
3017+
1. Let |keys| be a new [=/list=].
3018+
3019+
1. Let |values| be a new [=/list=].
3020+
3021+
1. [=list/For each=] |entry| of |entries|:
3022+
3023+
1. If |entry|'s [=list/size=] is not 2, [=exception/throw=] a {{TypeError}}.
3024+
3025+
1. [=list/Append=] |entry|[0] to |keys|.
3026+
3027+
Note: Keys are not [=convert a value to a key|converted=] until a subsequent step.
3028+
3029+
1. [=list/Append=] |entry|[1] to |values|.
3030+
3031+
1. Return the result of running [=add or put multiple records=] with [=/this=], |values|, false, and |keys|.
3032+
3033+
</div>
3034+
3035+
<div algorithm>
3036+
3037+
To <dfn>add or put multiple records</dfn> with |handle|, |values|, |no-overwrite flag|, and optional |keys|, run these steps:
3038+
3039+
1. [=/Assert=]: If |keys| is given, |values| [=list/size=] equals |keys| [=list/size=].
3040+
3041+
1. Let |transaction| be |handle|'s
3042+
[=object-store-handle/transaction=].
3043+
3044+
1. Let |store| be |handle|'s
3045+
[=object-store-handle/object store=].
3046+
3047+
1. If |store| has been deleted,
3048+
[=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
3049+
3050+
1. If |transaction|'s [=transaction/state=] is not [=transaction/active=],
3051+
then [=exception/throw=] a "{{TransactionInactiveError}}" {{DOMException}}.
3052+
3053+
1. If |transaction| is a [=transaction/read-only transaction=],
3054+
[=exception/throw=] a "{{ReadOnlyError}}" {{DOMException}}.
3055+
3056+
1. If |store| uses [=object-store/in-line keys=] and |keys| were given,
3057+
[=exception/throw=] a "{{DataError}}" {{DOMException}}.
3058+
3059+
1. If |store| uses [=object-store/out-of-line keys=] and has no [=key
3060+
generator=] and |keys| were not given, [=exception/throw=] a
3061+
"{{DataError}}" {{DOMException}}.
3062+
3063+
1. If |keys| were given, then:
3064+
3065+
1. Let |rs| be a new [=/list=].
3066+
3067+
1. [=list/For each=] |key| of |keys|:
3068+
3069+
1. Let |r| be the result of [=/converting a value to a key=] with |key|. Rethrow any exceptions.
3070+
3071+
1. If |r| is invalid, [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3072+
3073+
1. [=list/Append=] |r| to |rs|.
3074+
3075+
1. Let |keys| be |rs|.
3076+
3077+
1. Let |targetRealm| be a user-agent defined [=ECMAScript/Realm=].
3078+
3079+
1. Let |clones| be a new [=/list=].
3080+
3081+
1. [=list/For each=] |value| of |values|:
3082+
3083+
1. Let |clone| be a [=clone=] of |value| in |targetRealm| during |transaction|.
3084+
Rethrow any exceptions.
3085+
3086+
<details class=note>
3087+
<summary>Why create a copy of the value?</summary>
3088+
The value is serialized when stored. Treating it as a copy
3089+
here allows other algorithms in this specification to treat it as
3090+
an ECMAScript value, but implementations can optimize this
3091+
if the difference in behavior is not observable.
3092+
</details>
3093+
3094+
1. [=list/Append=] |clone| to |clones|.
3095+
3096+
1. If |store| uses [=object-store/in-line keys=], then:
3097+
3098+
1. Let |keys| be a new [=/list=].
3099+
3100+
1. [=list/For each=] |clone| of |clones|:
3101+
3102+
1. Let |key| be undefined.
3103+
3104+
1. Let |kpk| be the result of [=/extracting a key from a value using a key path=] with |clone| and |store|'s [=object-store/key path=]. Rethrow any exceptions.
3105+
3106+
1. If |kpk| is invalid, [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3107+
3108+
1. If |kpk| is not failure, let |key| be |kpk|.
3109+
3110+
1. Otherwise (|kpk| is failure):
3111+
3112+
1. If |store| does not have a [=key generator=], [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3113+
3114+
1. Otherwise, if [=check that a key could be injected into a value=] with |clone| and |store|'s [=object-store/key path=] return false, [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3115+
3116+
1. [=list/Append=] |key| to |keys|.
3117+
3118+
1. Let |operation| be an algorithm to run [=store multiple records into an object store=] with |store|, |clones|, |keys|, and |no-overwrite flag|.
3119+
3120+
1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.
3121+
29863122

29873123
</div>
29883124

@@ -5626,6 +5762,25 @@ To <dfn>store a record into an object store</dfn> with
56265762

56275763
</div>
56285764

5765+
<div algorithm>
5766+
5767+
To <dfn>store multiple records into an object store</dfn> with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps:
5768+
5769+
1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=].
5770+
5771+
1. Let |results| be a new [=/list=].
5772+
5773+
1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively:
5774+
5775+
1. Let |r| be the result of [=/storing a record into an object store=] with |store|, |value|, |key|, and |no-overwrite flag|.
5776+
5777+
1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|.
5778+
5779+
1. [=list/Append=] |r| to |results|.
5780+
5781+
1. Return |results|.
5782+
5783+
</div>
56295784

56305785
<!-- ============================================================ -->
56315786
## Object store retrieval operations ## {#object-store-retrieval-operation}
@@ -6706,6 +6861,7 @@ For the revision history of the second edition, see [that document's Revision Hi
67066861
* Added <a href="#accessibility">Accessibility considerations</a> section. ([Issue #327](https://github.com/w3c/IndexedDB/issues/327))
67076862
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
67086863
* Added a definition for [=transaction/live=] transactions, and renamed "run an upgrade transaction" to [=/upgrade a database=], to disambiguate "running". ([Issue #408](https://github.com/w3c/IndexedDB/issues/408))
6864+
* Added {{IDBObjectStore/putAllValues()}} and {{IDBObjectStore/putAllEntries()}} methods. ([Issue #69](https://github.com/w3c/IndexedDB/issues/69))
67096865

67106866
<!-- ============================================================ -->
67116867
# Acknowledgements # {#acknowledgements}
@@ -6769,6 +6925,7 @@ Marcos Cáceres,
67696925
Margo Seltzer,
67706926
Marijn Kruisselbrink,
67716927
Ms2ger,
6928+
Numfor Mbiziwo-tiapo,
67726929
Odin Omdal,
67736930
Olli Pettay,
67746931
Pablo Castro,

0 commit comments

Comments
 (0)