Skip to content

Commit cb96977

Browse files
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
1 parent af5536b commit cb96977

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
@@ -2736,6 +2736,8 @@ interface IDBObjectStore {
27362736
readonly attribute boolean autoIncrement;
27372737

27382738
[NewObject] IDBRequest put(any value, optional any key);
2739+
[NewObject] IDBRequest putAllValues(sequence<any> values);
2740+
[NewObject] IDBRequest putAllEntries(sequence<sequence<any>> entries);
27392741
[NewObject] IDBRequest add(any value, optional any key);
27402742
[NewObject] IDBRequest delete(any query);
27412743
[NewObject] IDBRequest clear();
@@ -2914,6 +2916,27 @@ and false otherwise.
29142916
If successful, |request|'s {{IDBRequest/result}} will be the
29152917
[=object-store/record=]'s [=/key=].
29162918

2919+
: |request| = |store| . {{IDBObjectStore/putAllValues()|putAllValues}}(|values|)
2920+
2921+
::
2922+
Adds or updates multiple [=object-store/records=] in |store| with the given array of |values|.
2923+
2924+
[=/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.
2925+
2926+
2927+
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}}.
2928+
2929+
2930+
: |request| = |store| . {{IDBObjectStore/putAllEntries()|putAllEntries}}(|entries|)
2931+
2932+
::
2933+
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.
2934+
2935+
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.
2936+
2937+
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}}.
2938+
2939+
29172940
: |request| = |store| .
29182941
{{IDBObjectStore/delete()|delete}}(|query|)
29192942
::
@@ -2932,13 +2955,13 @@ and false otherwise.
29322955
</div>
29332956

29342957

2935-
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.
2958+
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.
29362959

2937-
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.
2960+
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.
29382961

29392962
<div algorithm>
29402963

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

29432966
1. Let |transaction| be |handle|'s
29442967
[=object-store-handle/transaction=].
@@ -3009,6 +3032,119 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,
30093032

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

3035+
</div>
3036+
3037+
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.
3038+
3039+
<div algorithm>
3040+
3041+
The <dfn method for=IDBObjectStore>putAllEntries(|entries|)</dfn> method steps are:
3042+
3043+
1. Let |keys| be a new [=/list=].
3044+
3045+
1. Let |values| be a new [=/list=].
3046+
3047+
1. [=list/For each=] |entry| of |entries|:
3048+
3049+
1. If |entry|'s [=list/size=] is not 2, [=exception/throw=] a [=TypeError=].
3050+
3051+
1. [=list/Append=] |entry|[0] to |keys|.
3052+
3053+
Note: Keys are not [=convert a value to a key|converted=] until a subsequent step.
3054+
3055+
1. [=list/Append=] |entry|[1] to |values|.
3056+
3057+
1. Return the result of running [=add or put multiple records=] with [=/this=], |values|, false, and |keys|.
3058+
3059+
</div>
3060+
3061+
<div algorithm>
3062+
3063+
To <dfn>add or put multiple records</dfn> with |handle|, |values|, |no-overwrite flag|, and optional |keys|, run these steps:
3064+
3065+
1. [=/Assert=]: If |keys| is given, |values| [=list/size=] equals |keys| [=list/size=].
3066+
3067+
1. Let |transaction| be |handle|'s
3068+
[=object-store-handle/transaction=].
3069+
3070+
1. Let |store| be |handle|'s
3071+
[=object-store-handle/object store=].
3072+
3073+
1. If |store| has been deleted,
3074+
[=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
3075+
3076+
1. If |transaction|'s [=transaction/state=] is not [=transaction/active=],
3077+
then [=exception/throw=] a "{{TransactionInactiveError}}" {{DOMException}}.
3078+
3079+
1. If |transaction| is a [=transaction/read-only transaction=],
3080+
[=exception/throw=] a "{{ReadOnlyError}}" {{DOMException}}.
3081+
3082+
1. If |store| uses [=object-store/in-line keys=] and |keys| were given,
3083+
[=exception/throw=] a "{{DataError}}" {{DOMException}}.
3084+
3085+
1. If |store| uses [=object-store/out-of-line keys=] and has no [=key
3086+
generator=] and |keys| were not given, [=exception/throw=] a
3087+
"{{DataError}}" {{DOMException}}.
3088+
3089+
1. If |keys| were given, then:
3090+
3091+
1. Let |rs| be a new [=/list=].
3092+
3093+
1. [=list/For each=] |key| of |keys|:
3094+
3095+
1. Let |r| be the result of [=/converting a value to a key=] with |key|. Rethrow any exceptions.
3096+
3097+
1. If |r| is invalid, [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3098+
3099+
1. [=list/Append=] |r| to |rs|.
3100+
3101+
1. Let |keys| be |rs|.
3102+
3103+
1. Let |targetRealm| be a user-agent defined [=ECMAScript/Realm=].
3104+
3105+
1. Let |clones| be a new [=/list=].
3106+
3107+
1. [=list/For each=] |value| of |values|:
3108+
3109+
1. Let |clone| be a [=clone=] of |value| in |targetRealm| during |transaction|.
3110+
Rethrow any exceptions.
3111+
3112+
<details class=note>
3113+
<summary>Why create a copy of the value?</summary>
3114+
The value is serialized when stored. Treating it as a copy
3115+
here allows other algorithms in this specification to treat it as
3116+
an ECMAScript value, but implementations can optimize this
3117+
if the difference in behavior is not observable.
3118+
</details>
3119+
3120+
1. [=list/Append=] |clone| to |clones|.
3121+
3122+
1. If |store| uses [=object-store/in-line keys=], then:
3123+
3124+
1. Let |keys| be a new [=/list=].
3125+
3126+
1. [=list/For each=] |clone| of |clones|:
3127+
3128+
1. Let |key| be undefined.
3129+
3130+
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.
3131+
3132+
1. If |kpk| is invalid, [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3133+
3134+
1. If |kpk| is not failure, let |key| be |kpk|.
3135+
3136+
1. Otherwise (|kpk| is failure):
3137+
3138+
1. If |store| does not have a [=key generator=], [=exception/throw=] a "{{DataError}}" {{DOMException}}.
3139+
3140+
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}}.
3141+
3142+
1. [=list/Append=] |key| to |keys|.
3143+
3144+
1. Let |operation| be an algorithm to run [=store multiple records into an object store=] with |store|, |clones|, |keys|, and |no-overwrite flag|.
3145+
3146+
1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.
3147+
30123148

30133149
</div>
30143150

@@ -5713,6 +5849,25 @@ To <dfn>store a record into an object store</dfn> with
57135849

57145850
</div>
57155851

5852+
<div algorithm>
5853+
5854+
To <dfn>store multiple records into an object store</dfn> with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps:
5855+
5856+
1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=].
5857+
5858+
1. Let |results| be a new [=/list=].
5859+
5860+
1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively:
5861+
5862+
1. Let |r| be the result of [=/storing a record into an object store=] with |store|, |value|, |key|, and |no-overwrite flag|.
5863+
5864+
1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|.
5865+
5866+
1. [=list/Append=] |r| to |results|.
5867+
5868+
1. Return |results|.
5869+
5870+
</div>
57165871

57175872
<!-- ============================================================ -->
57185873
## Object store retrieval operations ## {#object-store-retrieval-operation}
@@ -6800,6 +6955,7 @@ For the revision history of the second edition, see [that document's Revision Hi
68006955
* Specified [[#transaction-scheduling]] more precisely and disallow starting read/write transactions while read-only transactions with overlapping scope are running. ([Issue #253](https://github.com/w3c/IndexedDB/issues/253))
68016956
* Added <a href="#accessibility">Accessibility considerations</a> section. ([Issue #327](https://github.com/w3c/IndexedDB/issues/327))
68026957
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
6958+
* Added {{IDBObjectStore/putAllValues()}} and {{IDBObjectStore/putAllEntries()}} methods. ([Issue #69](https://github.com/w3c/IndexedDB/issues/69))
68036959

68046960
<!-- ============================================================ -->
68056961
# Acknowledgements # {#acknowledgements}
@@ -6862,6 +7018,7 @@ Marcos Cáceres
68627018
Margo Seltzer,
68637019
Marijn Kruisselbrink,
68647020
Ms2ger,
7021+
Numfor Mbiziwo-tiapo,
68657022
Odin Omdal,
68667023
Olli Pettay,
68677024
Pablo Castro,

0 commit comments

Comments
 (0)