Skip to content

Commit f11de4f

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 7ff900f commit f11de4f

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
@@ -2717,6 +2717,8 @@ interface IDBObjectStore {
27172717
readonly attribute boolean autoIncrement;
27182718

27192719
[NewObject] IDBRequest put(any value, optional any key);
2720+
[NewObject] IDBRequest putAllValues(sequence<any> values);
2721+
[NewObject] IDBRequest putAllEntries(sequence<sequence<any>> entries);
27202722
[NewObject] IDBRequest add(any value, optional any key);
27212723
[NewObject] IDBRequest delete(any query);
27222724
[NewObject] IDBRequest clear();
@@ -2895,6 +2897,27 @@ and false otherwise.
28952897
If successful, |request|'s {{IDBRequest/result}} will be the
28962898
[=object-store/record=]'s [=/key=].
28972899

2900+
: |request| = |store| . {{IDBObjectStore/putAllValues()|putAllValues}}(|values|)
2901+
2902+
::
2903+
Adds or updates multiple [=object-store/records=] in |store| with the given array of |values|.
2904+
2905+
[=/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.
2906+
2907+
2908+
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}}.
2909+
2910+
2911+
: |request| = |store| . {{IDBObjectStore/putAllEntries()|putAllEntries}}(|entries|)
2912+
2913+
::
2914+
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.
2915+
2916+
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.
2917+
2918+
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}}.
2919+
2920+
28982921
: |request| = |store| .
28992922
{{IDBObjectStore/delete()|delete}}(|query|)
29002923
::
@@ -2913,13 +2936,13 @@ and false otherwise.
29132936
</div>
29142937

29152938

2916-
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.
2939+
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.
29172940

2918-
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.
2941+
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.
29192942

29202943
<div algorithm>
29212944

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

29242947
1. Let |transaction| be |handle|'s
29252948
[=object-store-handle/transaction=].
@@ -2990,6 +3013,119 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,
29903013

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

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

29943130
</div>
29953131

@@ -5694,6 +5830,25 @@ To <dfn>store a record into an object store</dfn> with
56945830

56955831
</div>
56965832

5833+
<div algorithm>
5834+
5835+
To <dfn>store multiple records into an object store</dfn> with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps:
5836+
5837+
1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=].
5838+
5839+
1. Let |results| be a new [=/list=].
5840+
5841+
1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively:
5842+
5843+
1. Let |r| be the result of [=/storing a record into an object store=] with |store|, |value|, |key|, and |no-overwrite flag|.
5844+
5845+
1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|.
5846+
5847+
1. [=list/Append=] |r| to |results|.
5848+
5849+
1. Return |results|.
5850+
5851+
</div>
56975852

56985853
<!-- ============================================================ -->
56995854
## Object store retrieval operations ## {#object-store-retrieval-operation}
@@ -6781,6 +6936,7 @@ For the revision history of the second edition, see [that document's Revision Hi
67816936
* 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))
67826937
* Added <a href="#accessibility">Accessibility considerations</a> section. ([Issue #327](https://github.com/w3c/IndexedDB/issues/327))
67836938
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
6939+
* Added {{IDBObjectStore/putAllValues()}} and {{IDBObjectStore/putAllEntries()}} methods. ([Issue #69](https://github.com/w3c/IndexedDB/issues/69))
67846940

67856941
<!-- ============================================================ -->
67866942
# Acknowledgements # {#acknowledgements}
@@ -6843,6 +6999,7 @@ Marcos Cáceres
68436999
Margo Seltzer,
68447000
Marijn Kruisselbrink,
68457001
Ms2ger,
7002+
Numfor Mbiziwo-tiapo,
68467003
Odin Omdal,
68477004
Olli Pettay,
68487005
Pablo Castro,

0 commit comments

Comments
 (0)