diff --git a/index.bs b/index.bs index 2a17d1e..302263e 100644 --- a/index.bs +++ b/index.bs @@ -2911,13 +2911,13 @@ and false otherwise. -The put(|value|, |key|) method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| false. +The put(|value|, |key|) 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. -The add(|value|, |key|) method steps are to return the result of running [=add or put=] with [=/this=], |value|, |key| and the |no-overwrite flag| true. +The add(|value|, |key|) 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.
-To add or put with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps: +To add or put a single record with |handle|, |value|, |key|, and |no-overwrite flag|, run these steps: 1. Let |transaction| be |handle|'s [=object-store-handle/transaction=]. @@ -2988,6 +2988,98 @@ To add or put with |handle|, |value|, |key|, and |no-overwrite flag|, 1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|. +
+ + +Issue: Define `putAll()` method(s) that use [=/add or put multiple records=]. + +
+ +To add or put multiple records with |handle|, |values|, |keys|, and |no-overwrite flag|, run these steps: + +1. [=/Assert=]: If |keys| is given, |values| [=list/size=] equals |keys| [=list/size=]. + +1. Let |transaction| be |handle|'s + [=object-store-handle/transaction=]. + +1. Let |store| be |handle|'s + [=object-store-handle/object store=]. + +1. If |store| has been deleted, + [=throw=] an "{{InvalidStateError}}" {{DOMException}}. + +1. If |transaction|'s [=transaction/state=] is not [=transaction/active=], + then [=throw=] a "{{TransactionInactiveError}}" {{DOMException}}. + +1. If |transaction| is a [=read-only transaction=], + [=throw=] a "{{ReadOnlyError}}" {{DOMException}}. + +1. If |store| uses [=in-line keys=] and |keys| were given, + [=throw=] a "{{DataError}}" {{DOMException}}. + +1. If |store| uses [=out-of-line keys=] and has no [=key + generator=] and |keys| were not given, [=throw=] a + "{{DataError}}" {{DOMException}}. + +1. If |keys| were given, then: + + 1. Let |rs| be a new [=/list=]. + + 1. [=list/For each=] |key| of |keys|: + + 1. Let |r| be the result of running [=convert a value to a key=] with |key|. Rethrow any exceptions. + + 1. If |r| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}. + + 1. [=list/Append=] |r| to |rs|. + + 1. Let |keys| be |rs|. + +1. Let |targetRealm| be a user-agent defined [=Realm=]. + +1. Let |clones| be a new [=/list=]. + +1. [=list/For each=] |value| of |values|: + + 1. Let |clone| be a [=clone=] of |value| in |targetRealm| during |transaction|. + Rethrow any exceptions. + +
+ Why create a copy of the value? + The value is serialized when stored. Treating it as a copy + here allows other algorithms in this specification to treat it as + an ECMAScript value, but implementations can optimize this + if the difference in behavior is not observable. +
+ + 1. [=list/Append=] |clone| to |clones|. + +1. If |store| uses [=in-line keys=], then: + + 1. Let |keys| be a new [=/list=]. + + 1. [=list/For each=] |clone| of |clones|: + + 1. Let |key| be undefined. + + 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. + + 1. If |kpk| is invalid, [=throw=] a "{{DataError}}" {{DOMException}}. + + 1. If |kpk| is not failure, let |key| be |kpk|. + + 1. Otherwise (|kpk| is failure): + + 1. If |store| does not have a [=key generator=], [=throw=] a "{{DataError}}" {{DOMException}}. + + 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}}. + + 1. [=list/Append=] |key| to |keys|. + +1. Let |operation| be an algorithm to run [=store multiple records into an object store=] with |store|, |clones|, |keys|, and |no-overwrite flag|. + +1. Return the result (an {{IDBRequest}}) of running [=asynchronously execute a request=] with |handle| and |operation|. +
@@ -5698,6 +5790,25 @@ To store a record into an object store with +
+ +To store multiple records into an object store with |store|, |values|, |keys|, and a |no-overwrite flag|, run these steps: + +1. [=/Assert=]: |values| [=list/size=] equals |keys| [=list/size=]. + +1. Let |results| be a new [=/list=]. + +1. [=list/For each=] |value| of |values| and |key| of |keys|, respectively: + + 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|. + + 1. If |r| is an error, then undo any changes made to |store| or associated [=/indexes=] by this algorithm, and return |r|. + + 1. [=list/Append=] |r| to |results|. + +1. Return |results|. + +
## Object store retrieval operations ## {#object-store-retrieval-operation}