Skip to content

Commit

Permalink
git squash commit for putall.
Browse files Browse the repository at this point in the history
f11de4f
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

58bd52cf997d061aa8cbe344b0baea713a2ae860
fix TypeError link
  • Loading branch information
inexorabletash committed Apr 13, 2023
1 parent a6a3acc commit 7d66df9
Showing 1 changed file with 160 additions and 3 deletions.
163 changes: 160 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,8 @@ interface IDBObjectStore {
readonly attribute boolean autoIncrement;

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

: |request| = |store| . {{IDBObjectStore/putAllValues()|putAllValues}}(|values|)

::
Adds or updates multiple [=object-store/records=] in |store| with the given array of |values|.

[=/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.


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}}.


: |request| = |store| . {{IDBObjectStore/putAllEntries()|putAllEntries}}(|entries|)

::
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.

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.

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}}.


: |request| = |store| .
{{IDBObjectStore/delete()|delete}}(|query|)
::
Expand All @@ -2913,13 +2936,13 @@ and false otherwise.
</div>


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.
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.

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.
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.

<div algorithm>

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

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

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

</div>

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.

<div algorithm>

The <dfn method for=IDBObjectStore>putAllEntries(|entries|)</dfn> method steps are:

1. Let |keys| be a new [=/list=].

1. Let |values| be a new [=/list=].

1. [=list/For each=] |entry| of |entries|:

1. If |entry|'s [=list/size=] is not 2, [=exception/throw=] a {{TypeError}}.

1. [=list/Append=] |entry|[0] to |keys|.

Note: Keys are not [=convert a value to a key|converted=] until a subsequent step.

1. [=list/Append=] |entry|[1] to |values|.

1. Return the result of running [=add or put multiple records=] with [=/this=], |values|, false, and |keys|.

</div>

<div algorithm>

To <dfn>add or put multiple records</dfn> with |handle|, |values|, |no-overwrite flag|, and optional |keys|, 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,
[=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.

1. If |transaction|'s [=transaction/state=] is not [=transaction/active=],
then [=exception/throw=] a "{{TransactionInactiveError}}" {{DOMException}}.

1. If |transaction| is a [=transaction/read-only transaction=],
[=exception/throw=] a "{{ReadOnlyError}}" {{DOMException}}.

1. If |store| uses [=object-store/in-line keys=] and |keys| were given,
[=exception/throw=] a "{{DataError}}" {{DOMException}}.

1. If |store| uses [=object-store/out-of-line keys=] and has no [=key
generator=] and |keys| were not given, [=exception/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 [=/converting a value to a key=] with |key|. Rethrow any exceptions.

1. If |r| is invalid, [=exception/throw=] a "{{DataError}}" {{DOMException}}.

1. [=list/Append=] |r| to |rs|.

1. Let |keys| be |rs|.

1. Let |targetRealm| be a user-agent defined [=ECMAScript/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.

<details class=note>
<summary>Why create a copy of the value?</summary>
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.
</details>

1. [=list/Append=] |clone| to |clones|.

1. If |store| uses [=object-store/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 [=/extracting 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, [=exception/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=], [=exception/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, [=exception/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|.


</div>

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

</div>

<div algorithm>

To <dfn>store multiple records into an object store</dfn> 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 [=/storing 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|.

</div>

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

<!-- ============================================================ -->
# Acknowledgements # {#acknowledgements}
Expand Down Expand Up @@ -6843,6 +6999,7 @@ Marcos Cáceres
Margo Seltzer,
Marijn Kruisselbrink,
Ms2ger,
Numfor Mbiziwo-tiapo,
Odin Omdal,
Olli Pettay,
Pablo Castro,
Expand Down

0 comments on commit 7d66df9

Please sign in to comment.