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
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}}.
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
+
2891
2914
: |request| = |store| .
2892
2915
{{IDBObjectStore/delete()|delete}}(|query|)
2893
2916
::
@@ -2906,13 +2929,13 @@ and false otherwise.
2906
2929
</div>
2907
2930
2908
2931
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.
2910
2933
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.
2912
2935
2913
2936
<div algorithm>
2914
2937
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:
2916
2939
2917
2940
1. Let |transaction| be |handle|'s
2918
2941
[=object-store-handle/transaction=].
@@ -2983,6 +3006,119 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,
2983
3006
2984
3007
1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.
2985
3008
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
+
2986
3122
2987
3123
</div>
2988
3124
@@ -5626,6 +5762,25 @@ To <dfn>store a record into an object store</dfn> with
5626
5762
5627
5763
</div>
5628
5764
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:
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
6708
6863
* 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))
0 commit comments