Skip to content

Commit eae8b52

Browse files
Initial algorithms for putAll
1 parent e6133a1 commit eae8b52

File tree

1 file changed

+114
-3
lines changed

1 file changed

+114
-3
lines changed

index.bs

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,13 +2911,13 @@ and false otherwise.
29112911
</div>
29122912

29132913

2914-
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.
2914+
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 the |no-overwrite flag| false.
29152915

2916-
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.
2916+
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 the |no-overwrite flag| true.
29172917

29182918
<div algorithm>
29192919

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

29222922
1. Let |transaction| be |handle|'s
29232923
[=object-store-handle/transaction=].
@@ -2988,6 +2988,98 @@ To <dfn>add or put</dfn> with |handle|, |value|, |key|, and |no-overwrite flag|,
29882988

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

2991+
</div>
2992+
2993+
2994+
Issue: Define `putAll()` method(s) that use [=/add or put multiple records=].
2995+
2996+
<div algorithm>
2997+
2998+
To <dfn>add or put multiple records</dfn> with |handle|, |values|, |keys|, and |no-overwrite flag|, run these steps:
2999+
3000+
1. [=/Assert=]: If |keys| is given, |values| [=list/size=] equals |keys| [=list/size=].
3001+
3002+
1. Let |transaction| be |handle|'s
3003+
[=object-store-handle/transaction=].
3004+
3005+
1. Let |store| be |handle|'s
3006+
[=object-store-handle/object store=].
3007+
3008+
1. If |store| has been deleted,
3009+
[=throw=] an "{{InvalidStateError}}" {{DOMException}}.
3010+
3011+
1. If |transaction|'s [=transaction/state=] is not [=transaction/active=],
3012+
then [=throw=] a "{{TransactionInactiveError}}" {{DOMException}}.
3013+
3014+
1. If |transaction| is a [=read-only transaction=],
3015+
[=throw=] a "{{ReadOnlyError}}" {{DOMException}}.
3016+
3017+
1. If |store| uses [=in-line keys=] and |keys| were given,
3018+
[=throw=] a "{{DataError}}" {{DOMException}}.
3019+
3020+
1. If |store| uses [=out-of-line keys=] and has no [=key
3021+
generator=] and |keys| were not given, [=throw=] a
3022+
"{{DataError}}" {{DOMException}}.
3023+
3024+
1. If |keys| were given, then:
3025+
3026+
1. Let |rs| be a new [=/list=].
3027+
3028+
1. [=list/For each=] |key| of |keys|:
3029+
3030+
1. Let |r| be the result of running [=convert a value to a key=] with |key|. Rethrow any exceptions.
3031+
3032+
1. If |r| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}.
3033+
3034+
1. [=list/Append=] |r| to |rs|.
3035+
3036+
1. Let |keys| be |rs|.
3037+
3038+
1. Let |targetRealm| be a user-agent defined [=Realm=].
3039+
3040+
1. Let |clones| be a new [=/list=].
3041+
3042+
1. [=list/For each=] |value| of |values|:
3043+
3044+
1. Let |clone| be a [=clone=] of |value| in |targetRealm| during |transaction|.
3045+
Rethrow any exceptions.
3046+
3047+
<details class=note>
3048+
<summary>Why create a copy of the value?</summary>
3049+
The value is serialized when stored. Treating it as a copy
3050+
here allows other algorithms in this specification to treat it as
3051+
an ECMAScript value, but implementations can optimize this
3052+
if the difference in behavior is not observable.
3053+
</details>
3054+
3055+
1. [=list/Append=] |clone| to |clones|.
3056+
3057+
1. If |store| uses [=in-line keys=], then:
3058+
3059+
1. Let |keys| be a new [=/list=].
3060+
3061+
1. [=list/For each=] |clone| of |clones|:
3062+
3063+
1. Let |key| be undefined.
3064+
3065+
1. Let |kpk| be the result of running [=extract a key from a value using a key path=] with |clone| and |store|'s [=object-store/key path=]. Rethrow any exceptions.
3066+
3067+
1. If |kpk| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}.
3068+
3069+
1. If |kpk| is not failure, let |key| be |kpk|.
3070+
3071+
1. Otherwise (|kpk| is failure):
3072+
3073+
1. If |store| does not have a [=key generator=], [=throw=] a "{{DataError}}" {{DOMException}}.
3074+
3075+
1. Otherwise, if [=check that a key could be injected into a value=] with |clone| and |store|'s [=object-store/key path=] return false, [=throw=] a "{{DataError}}" {{DOMException}}.
3076+
3077+
1. [=list/Append=] |key| to |keys|.
3078+
3079+
1. Let |operation| be an algorithm to run [=store multiple records into an object store=] with |store|, |clones|, |keys|, and |no-overwrite flag|.
3080+
3081+
1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|.
3082+
29913083

29923084
</div>
29933085

@@ -5698,6 +5790,25 @@ To <dfn>store a record into an object store</dfn> with
56985790

56995791
</div>
57005792

5793+
<div algorithm>
5794+
5795+
To <dfn>store multiple records into an object store</dfn> with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps:
5796+
5797+
1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=].
5798+
5799+
1. Let |results| be a new [=/list=].
5800+
5801+
1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively:
5802+
5803+
1. Let |r| be the result of running the steps [=store a record into an object store=] with |store|, |value|, |key|, and |no-overwrite flag|.
5804+
5805+
1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|.
5806+
5807+
1. [=list/Append=] |r| to |results|.
5808+
5809+
1. Return |results|.
5810+
5811+
</div>
57015812

57025813
<!-- ============================================================ -->
57035814
## Object store retrieval operations ## {#object-store-retrieval-operation}

0 commit comments

Comments
 (0)