Skip to content

Commit d669216

Browse files
git squash commit for manualcommit.
461db42e966892b49eb9f689c20d1e4fcde0f618 Initial sketch of manual commit fix/add 'new in this edition' hints version history invert flag check don't let tx go inactive post-rebase cleanup 6fbe9e5f5221c00700c1b2e2a0707249177f4414 bangbang
1 parent a6a3acc commit d669216

File tree

1 file changed

+124
-16
lines changed

1 file changed

+124
-16
lines changed

index.bs

Lines changed: 124 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ following:
929929
instead is created automatically when an
930930
{{IDBOpenDBRequest/upgradeneeded!!event}} event is fired.
931931

932+
A [=/transaction=] has an <dfn>manual commit flag</dfn>, which is initially false. By default, transactions commit automatically when all outstanding requests have been processed. This can be behavior can be modified by options set when creating the transaction.
933+
932934
A [=/transaction=] has a <dfn>durability hint</dfn>. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction. The [=transaction/durability hint=] is one of the following:
933935

934936
: "{{IDBTransactionDurability/strict}}"
@@ -1036,10 +1038,11 @@ The <dfn>lifetime</dfn> of a
10361038
</aside>
10371039

10381040
1. When each [=/request=] associated with a transaction is [=request/processed=],
1039-
a {{IDBRequest/success!!event}} or {{IDBRequest/error!!event}} [=event=] will be
1040-
fired. While the event is being [=dispatched=], the transaction
1041+
a {{IDBRequest/success!!event}} or {{IDBRequest/error!!event}} [=event=] will be fired.
1042+
If the transaction's [=transaction/manual commit flag=] is false (the default), then
1043+
while the event is being [=dispatched=], the transaction
10411044
[=transaction/state=] is set to [=transaction/active=], allowing
1042-
additional requests to be made against the transaction. Once the
1045+
additional requests to be made against the transaction; once the
10431046
event dispatch is complete, the transaction's
10441047
[=transaction/state=] is set to [=transaction/inactive=] again.
10451048

@@ -1058,11 +1061,12 @@ The <dfn>lifetime</dfn> of a
10581061
[=/object stores=] as well as additions and removals of [=/object
10591062
stores=] and [=/indexes=].
10601063

1061-
1. The implementation must attempt to <dfn lt="commit|committed">commit</dfn>
1062-
a transaction when all [=/requests=] placed against the
1064+
1. If a transaction's [=transaction/manual commit flag=] is false, then
1065+
the implementation must attempt to <dfn lt="commit|committed">commit</dfn>
1066+
it when all [=/requests=] placed against the
10631067
transaction have completed and their returned results handled, no
10641068
new requests have been placed against the transaction, and the
1065-
transaction has not been [=transaction/aborted=]
1069+
transaction has not been [=transaction/aborted=].
10661070

10671071
An explicit call to {{IDBTransaction/commit()}} will initiate a
10681072
[=transaction/commit=] without waiting for request results to be
@@ -1099,7 +1103,7 @@ They will return true if any transactions were cleaned up, or false otherwise.
10991103
1. For each [=/transaction=] |transaction| with [=transaction/cleanup event loop=]
11001104
matching the current [=/event loop=]:
11011105

1102-
1. Set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
1106+
1. If |transaction|'s [=transaction/manual commit flag=] is false, then set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
11031107

11041108
1. Clear |transaction|'s [=transaction/cleanup event loop=].
11051109

@@ -1120,6 +1124,78 @@ a [=/transaction=] that has successfully [=transaction/committed=].
11201124
An event with type <dfn event for=IDBTransaction>abort</dfn> is fired at
11211125
a [=/transaction=] that has [=transaction/aborted=].
11221126

1127+
1128+
<aside class=example id=example-transaction-autocommit>
1129+
1130+
The following example uses requests within a transaction to increment a counter value.
1131+
Event handlers log various state changes during the request and transaction lifecycles.
1132+
1133+
```js
1134+
const transaction = connection.transaction('my_data', 'readwrite');
1135+
const store = transaction.objectStore('my_data');
1136+
const get_request = store.get('counter');
1137+
get_request.onerror = e => {
1138+
console.warn(`get failed: ${get_request.error}`);
1139+
};
1140+
get_request.onsuccess = e => {
1141+
console.log(`get succeeded`);
1142+
const old_value = get_request.result;
1143+
const put_request = store.put(old_value + 1, 'counter');
1144+
put_request.onerror = e => {
1145+
console.warn(`get failed: ${put_request.error}`);
1146+
};
1147+
put_request.onsuccess = {
1148+
console.log(`put succeeded`);
1149+
// No more requests are made, so the transaction will autocommit.
1150+
};
1151+
};
1152+
1153+
transaction.onabort = e => {
1154+
console.warn(`transaction aborted: ${transaction.error}`);
1155+
};
1156+
1157+
transaction.oncomplete = e => {
1158+
console.log(`transaction committed`);
1159+
};
1160+
```
1161+
</aside>
1162+
1163+
<aside class=example id=example-transaction-manualcommit>
1164+
1165+
The following example uses requests within a transaction to atomically
1166+
update a record's value using an asynchronous network fetch. A manually
1167+
committing transaction is necessary.
1168+
1169+
```js
1170+
const transaction = connection.transaction(
1171+
'my_records, 'readwrite', {manualCommit: true});
1172+
1173+
const store = transaction.objectStore('my_records);
1174+
store.get('key').onsuccess = async e => {
1175+
try {
1176+
const record = e.target.result;
1177+
1178+
// Make an asynchronous network request. If the transaction
1179+
// was not set to manual commit, it would autocommit here
1180+
// because there were no outstanding requests.
1181+
const response = await fetch(record.url);
1182+
1183+
// Update the record.
1184+
record.status = response.status;
1185+
store.put(record, 'key');
1186+
1187+
// Commit the transaction, once the request has completed.
1188+
// If the request fails, the transaction will abort instead.
1189+
transaction.commit();
1190+
} catch (ex) {
1191+
// If the fetch() fails, abort the transaction.
1192+
transaction.abort();
1193+
}
1194+
});
1195+
```
1196+
</aside>
1197+
1198+
11231199
<!-- ============================================================ -->
11241200
### Transaction scheduling ### {#transaction-scheduling}
11251201
<!-- ============================================================ -->
@@ -2429,6 +2505,7 @@ interface IDBDatabase : EventTarget {
24292505
enum IDBTransactionDurability { "default", "strict", "relaxed" };
24302506

24312507
dictionary IDBTransactionOptions {
2508+
boolean manualCommit = false;
24322509
IDBTransactionDurability durability = "default";
24332510
};
24342511

@@ -2622,9 +2699,13 @@ instance on which it was called.
26222699
Returns a new [=/transaction=] with the given
26232700
|scope| (which can be a single [=/object store=] [=object-store/name=] or an array of [=object-store/names=]),
26242701
|mode| ("{{IDBTransactionMode/readonly}}" or "{{IDBTransactionMode/readwrite}}"),
2625-
and additional |options| including {{IDBTransactionOptions/durability}} ("{{IDBTransactionDurability/default}}", "{{IDBTransactionDurability/strict}}" or "{{IDBTransactionDurability/relaxed}}").
2702+
and additional |options| including
2703+
{{IDBTransactionOptions/manualCommit}} (true or false), and
2704+
{{IDBTransactionOptions/durability}} ("{{IDBTransactionDurability/default}}", "{{IDBTransactionDurability/strict}}" or "{{IDBTransactionDurability/relaxed}}").
26262705

2627-
The default |mode| is "{{IDBTransactionMode/readonly}}" and the default {{IDBTransactionOptions/durability}} is "{{IDBTransactionDurability/default}}".
2706+
The default |mode| is "{{IDBTransactionMode/readonly}}".
2707+
The default {{IDBTransactionOptions/manualCommit}} is false.
2708+
The default {{IDBTransactionOptions/durability}} is "{{IDBTransactionDurability/default}}".
26282709

26292710
: |connection| . {{IDBDatabase/close()|close}}()
26302711
::
@@ -2655,7 +2736,11 @@ The <dfn method for=IDBDatabase>transaction(|storeNames|, |mode|, |options|)</df
26552736
1. If |mode| is not "{{IDBTransactionMode/readonly}}" or "{{IDBTransactionMode/readwrite}}",
26562737
[=exception/throw=] a {{TypeError}}.
26572738

2658-
1. Let |transaction| be a newly [=transaction/created=] [=/transaction=] with this [=/connection=], |mode|, |options|' {{IDBTransactionOptions/durability}} member, and the set of [=/object stores=] named in |scope|.
2739+
1. Let |transaction| be a newly [=transaction/created=] [=/transaction=] with this [=/connection=], |mode|, and the set of [=/object stores=] named in |scope|.
2740+
2741+
1. Set |transaction|'s [=transaction/manual commit flag=] to |options|' {{IDBTransactionOptions/manualCommit}} member.
2742+
2743+
1. Set |transaction|'s [=transaction/durability hint=] to |options|' {{IDBTransactionOptions/durability}} member.
26592744

26602745
1. Set |transaction|'s [=transaction/cleanup event loop=] to the
26612746
current [=/event loop=].
@@ -2664,6 +2749,12 @@ The <dfn method for=IDBDatabase>transaction(|storeNames|, |mode|, |options|)</df
26642749

26652750
</div>
26662751

2752+
<aside class=advisement>
2753+
&#x1F6A7;
2754+
The {{IDBTransactionOptions/manualCommit}} option is new in this edition.
2755+
&#x1F6A7;
2756+
</aside>
2757+
26672758
<aside class=advisement>
26682759
&#x1F6A7;
26692760
The {{IDBTransactionOptions/durability}} option is new in this edition.
@@ -4719,6 +4810,7 @@ the contents of the database.
47194810
interface IDBTransaction : EventTarget {
47204811
readonly attribute DOMStringList objectStoreNames;
47214812
readonly attribute IDBTransactionMode mode;
4813+
readonly attribute boolean manualCommit;
47224814
readonly attribute IDBTransactionDurability durability;
47234815
[SameObject] readonly attribute IDBDatabase db;
47244816
readonly attribute DOMException? error;
@@ -4753,6 +4845,10 @@ enum IDBTransactionMode {
47534845
("{{IDBTransactionMode/readonly}}" or "{{IDBTransactionMode/readwrite}}"), or "{{IDBTransactionMode/versionchange}}" for
47544846
an [=/upgrade transaction=].
47554847

4848+
: |transaction| . {{IDBTransaction/manualCommit}}
4849+
::
4850+
Returns true if the transaction was created with {{IDBTransactionOptions/manualCommit}}: `true` and false otherwise.
4851+
47564852
: |transaction| . {{IDBTransaction/durability}}
47574853
::
47584854
Returns the [=transaction/durability hint=] the transaction was created with
@@ -4788,6 +4884,14 @@ The <dfn attribute for=IDBTransaction>objectStoreNames</dfn> getter steps are:
47884884
The <dfn attribute for=IDBTransaction>mode</dfn> getter steps are to
47894885
return [=/this=]'s [=transaction/mode=].
47904886

4887+
The <dfn attribute for=IDBTransaction>manualCommit</dfn> attribute's getter must return [=/this=]'s [=transaction/manual commit flag=].
4888+
4889+
<aside class=advisement>
4890+
&#x1F6A7;
4891+
The {{IDBTransaction/manualCommit}} attribute is new in this edition.
4892+
&#x1F6A7;
4893+
</aside>
4894+
47914895
The <dfn attribute for=IDBTransaction>durability</dfn> getter steps are to return [=/this=]'s [=transaction/durability hint=].
47924896

47934897
<aside class=advisement>
@@ -4797,7 +4901,6 @@ The <dfn attribute for=IDBTransaction>durability</dfn> getter steps are to retur
47974901
&#x1F6A7;
47984902
</aside>
47994903

4800-
48014904
The <dfn attribute for=IDBTransaction>db</dfn> getter steps are to
48024905
return [=/this=]'s [=transaction/connection=]'s associated [=/database=].
48034906

@@ -4835,6 +4938,9 @@ none.
48354938
transaction to quickly finish, without waiting for pending requests to fire
48364939
{{IDBRequest/success!!event}} events before attempting to commit normally.
48374940

4941+
If the transaction was created with `manualCommit: true` then this method
4942+
<span class=allow-2119>must</span> be called to commit the transaction.
4943+
48384944
The transaction will abort if a pending request fails, for example due to a
48394945
constraint error. The {{IDBRequest/success!!event}} events for successful requests
48404946
will still fire, but throwing an exception in an event handler will not abort
@@ -4891,7 +4997,8 @@ The <dfn method for=IDBTransaction>abort()</dfn> method steps are:
48914997

48924998
The <dfn method for=IDBTransaction>commit()</dfn> method steps are:
48934999

4894-
1. If [=/this=]'s [=transaction/state=] is not [=transaction/active=],
5000+
1. If [=/this=]'s [=transaction/manual commit flag=] is false,
5001+
and [=/this=]'s [=transaction/state=] is not [=transaction/active=],
48955002
then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
48965003

48975004
1. Run [=commit a transaction=] with [=/this=].
@@ -5480,14 +5587,14 @@ To <dfn>fire a success event</dfn> at a |request|, run these steps:
54805587
1. If |transaction|'s [=transaction/state=] is [=transaction/active=],
54815588
then:
54825589

5483-
1. Set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
5590+
1. If |transaction|'s [=transaction/manual commit flag=] is false, then set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
54845591

54855592
1. If |legacyOutputDidListenersThrowFlag| is true,
54865593
then run [=abort a transaction=] with
54875594
|transaction| and a newly [=exception/created=]
54885595
"{{AbortError}}" {{DOMException}}.
54895596

5490-
1. If |transaction|'s [=transaction/request list=] is empty,
5597+
1. If |transaction|'s [=transaction/manual commit flag=] is false and if |transaction|'s [=transaction/request list=] is empty,
54915598
then run [=commit a transaction=] with |transaction|.
54925599

54935600
</div>
@@ -5519,7 +5626,7 @@ To <dfn>fire an error event</dfn> at a |request|, run these steps:
55195626
1. If |transaction|'s [=transaction/state=] is [=transaction/active=],
55205627
then:
55215628

5522-
1. Set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
5629+
1. If |transaction|'s [=transaction/manual commit flag=] is false, then set |transaction|'s [=transaction/state=] to [=transaction/inactive=].
55235630

55245631
1. If |legacyOutputDidListenersThrowFlag| is true,
55255632
then run [=abort a transaction=] with
@@ -5540,7 +5647,7 @@ To <dfn>fire an error event</dfn> at a |request|, run these steps:
55405647
|transaction| and [=/request=]'s [=request/error=], and
55415648
terminate these steps.
55425649

5543-
1. If |transaction|'s [=transaction/request list=] is empty,
5650+
1. If |transaction|'s [=transaction/manual commit flag=] is false and |transaction|'s [=transaction/request list=] is empty,
55445651
then run [=commit a transaction=] with |transaction|.
55455652

55465653
</div>
@@ -6781,6 +6888,7 @@ For the revision history of the second edition, see [that document's Revision Hi
67816888
* 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))
67826889
* Added <a href="#accessibility">Accessibility considerations</a> section. ([Issue #327](https://github.com/w3c/IndexedDB/issues/327))
67836890
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
6891+
* Specified [=transaction/manual commit flag=], {{IDBTransactionOptions/manualCommit}} option and {{IDBTransaction/manualCommit}} attribute. ([Issue #34](https://github.com/w3c/IndexedDB/issues/34))
67846892

67856893
<!-- ============================================================ -->
67866894
# Acknowledgements # {#acknowledgements}

0 commit comments

Comments
 (0)