File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,38 @@ class CdsUser extends API::Node {
586
586
}
587
587
}
588
588
589
+ /**
590
+ * A transaction object to be carried out by a service that it is initialized
591
+ * with through a call to `tx`. Note that there are two types of styles when
592
+ * it comes to using the transaction object, that is, within a callback or in a
593
+ * `try`-`catch` block:
594
+ *
595
+ * ``` javascript
596
+ * // 1. The transaction object is bound to a callback and is used in its body.
597
+ * await srv.tx({ user: someUser }, async (tx) => {
598
+ * tx.run(SELECT.from`Entity`.where`attr=${attr}`);
599
+ * });
600
+ *
601
+ * // 2. The transaction object is used in a try-catch block, in a manual manner.
602
+ * let tx = this.tx();
603
+ * try {
604
+ * tx.run(SELECT.from`Entity`.where`attr=${attr}`);
605
+ * await tx.commit();
606
+ * } catch (e) {
607
+ * await tx.rollback(e);
608
+ * }
609
+ * ```
610
+ *
611
+ * The former style allows for automatic transaction management by the framework
612
+ * (notice there are no `commit` and `rollback` calls), while the latter style
613
+ * makes the low-level transaction operations explicit.
614
+ *
615
+ * To accommodate for both styles, this class captures both the transaction call
616
+ * itself, and the parameter of the callback.
617
+ *
618
+ * Note that the call to `tx` can optionally take a context object as its first
619
+ * parameter that lets overriding of certain options such as `user`.
620
+ */
589
621
class CdsTransaction extends SourceNode {
590
622
ServiceInstance srv ;
591
623
CallNode txCall ;
You can’t perform that action at this time.
0 commit comments