You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/using/js/client.rst
+41-2Lines changed: 41 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,14 +187,14 @@ Both ``execute`` and the ``query*`` methods support scripts (queries containing
187
187
});
188
188
result; // { id: string }[]: the result of the `insert Person` statement
189
189
190
-
For more fine grained control of atomic exectution of multiple statements, use the ``transaction()`` API.
190
+
For more fine grained control of atomic execution of multiple statements, use the ``transaction()`` API.
191
191
192
192
.. _gel-js-api-transaction:
193
193
194
194
Transactions
195
195
------------
196
196
197
-
For more fine grained control of atomic exectution of multiple statements, use the ``transaction()`` API.
197
+
For more fine grained control of atomic execution of multiple statements, use the ``transaction()`` API.
198
198
199
199
.. code-block:: typescript
200
200
@@ -213,6 +213,8 @@ The ``transaction()`` API guarantees that:
213
213
214
214
The *transaction* object exposes ``query()``, ``execute()``, ``querySQL()``, ``executeSQL()``, and other ``query*()`` methods that *clients* expose, with the only difference that queries will run within the current transaction and can be retried automatically.
215
215
216
+
Default isolation level is serializable. You can change it via ``Client.withTransactionOptions``.
217
+
216
218
.. warning::
217
219
218
220
In transactions, the entire nested code block can be re-run, including any non-querying JavaScript code. In general, the code inside the transaction block **should not have side effects or run for a significant amount of time**. Consider the following example:
@@ -628,6 +630,9 @@ Client Reference
628
630
);
629
631
});
630
632
633
+
By default, transactions will be executed in the strictest, serializable isolation level.
634
+
To change the isolation level, use the ``Client.withTransactionOptions``.
635
+
631
636
.. js:method::ensureConnected():Promise<Client>
632
637
633
638
If the client does not yet have any open connections in its pool, attempts to open a connection, else returns immediately.
@@ -743,6 +748,40 @@ Client Reference
743
748
// ...
744
749
});
745
750
751
+
.. js:method::withTransactionOptions(opts: {
752
+
isolation?: IsolationLevel, \
753
+
readonly?: boolean, \
754
+
deferrable?: boolean, \
755
+
}): Client
756
+
757
+
Returns a clone of the ``Client`` instance with the specified transaction options.
758
+
759
+
Available isolation levels are ``Serializable``, ``RepeatableRead``, and ``PreferRepeatableRead``. ``PreferRepeatableRead`` uses repeatable read isolation level if server analysis concludes that it is supported for a given query. Otherwise, uses serializable isolation level.
760
+
761
+
When readonly is set, the transaction is now allowed to execute ``insert``, ``update``, or ``delete`` statements.
762
+
763
+
When deferrable is set, and isolation is serializable and readonly is set, the transaction only block when first acquiring its snapshot, after which it is able to run without the normal overhead of a serializable transaction and without any risk of contributing to or being canceled by a serialization failure. This mode is well suited for long-running reports or backups.
764
+
765
+
For more information, see :ref:`the transaction options reference <ref_eql_statements_start_tx>`.
766
+
767
+
:arg opts: An object mapping transaction options to values.
Returns a clone of the ``Client`` instance with the specified warning handler. Some queries may generate warnings while still returning a result. The ``handler`` function will be called with an array of ``GelError`` objects whenever the client encounters warnings during query execution.
0 commit comments