UNPKG

3.36 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = void 0;
9
10var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
12var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
14var _rxjs = require("rxjs");
15
16var _resultRx = _interopRequireDefault(require("./result-rx"));
17
18var _neo4jDriverCore = _interopRequireDefault(require("neo4j-driver-core"));
19
20/**
21 * Copyright (c) "Neo4j"
22 * Neo4j Sweden AB [http://neo4j.com]
23 *
24 * This file is part of Neo4j.
25 *
26 * Licensed under the Apache License, Version 2.0 (the "License");
27 * you may not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS,
34 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
37 */
38
39/**
40 * A reactive transaction, which provides the same functionality as {@link Transaction} but through a Reactive API.
41 */
42var RxTransaction = /*#__PURE__*/function () {
43 /**
44 * @constructor
45 * @protected
46 * @param {Transaction} txc - The underlying transaction instance to relay requests
47 */
48 function RxTransaction(txc) {
49 (0, _classCallCheck2["default"])(this, RxTransaction);
50 this._txc = txc;
51 }
52 /**
53 * Creates a reactive result that will execute the query in this transaction, with the provided parameters.
54 *
55 * @public
56 * @param {string} query - Query to be executed.
57 * @param {Object} parameters - Parameter values to use in query execution.
58 * @returns {RxResult} - A reactive result
59 */
60
61
62 (0, _createClass2["default"])(RxTransaction, [{
63 key: "run",
64 value: function run(query, parameters) {
65 var _this = this;
66
67 return new _resultRx["default"](new _rxjs.Observable(function (observer) {
68 try {
69 observer.next(_this._txc.run(query, parameters));
70 observer.complete();
71 } catch (err) {
72 observer.error(err);
73 }
74
75 return function () {};
76 }));
77 }
78 /**
79 * Commits the transaction.
80 *
81 * @public
82 * @returns {Observable} - An empty observable
83 */
84
85 }, {
86 key: "commit",
87 value: function commit() {
88 var _this2 = this;
89
90 return new _rxjs.Observable(function (observer) {
91 _this2._txc.commit().then(function () {
92 observer.complete();
93 })["catch"](function (err) {
94 return observer.error(err);
95 });
96 });
97 }
98 /**
99 * Rolls back the transaction.
100 *
101 * @public
102 * @returns {Observable} - An empty observable
103 */
104
105 }, {
106 key: "rollback",
107 value: function rollback() {
108 var _this3 = this;
109
110 return new _rxjs.Observable(function (observer) {
111 _this3._txc.rollback().then(function () {
112 observer.complete();
113 })["catch"](function (err) {
114 return observer.error(err);
115 });
116 });
117 }
118 }]);
119 return RxTransaction;
120}();
121
122exports["default"] = RxTransaction;
\No newline at end of file