UNPKG

3.37 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 _transaction = _interopRequireDefault(require("./transaction"));
19
20/**
21 * Copyright (c) 2002-2019 "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 =
43/*#__PURE__*/
44function () {
45 /**
46 * @constructor
47 * @protected
48 * @param {Transaction} txc - The underlying transaction instance to relay requests
49 */
50 function RxTransaction(txc) {
51 (0, _classCallCheck2["default"])(this, RxTransaction);
52 this._txc = txc;
53 }
54 /**
55 * Creates a reactive result that will execute the query in this transaction, with the provided parameters.
56 *
57 * @public
58 * @param {string} query - Query to be executed.
59 * @param {Object} parameters - Parameter values to use in query execution.
60 * @returns {RxResult} - A reactive result
61 */
62
63
64 (0, _createClass2["default"])(RxTransaction, [{
65 key: "run",
66 value: function run(query, parameters) {
67 var _this = this;
68
69 return new _resultRx["default"](new _rxjs.Observable(function (observer) {
70 try {
71 observer.next(_this._txc.run(query, parameters));
72 observer.complete();
73 } catch (err) {
74 observer.error(err);
75 }
76
77 return function () {};
78 }));
79 }
80 /**
81 * Commits the transaction.
82 *
83 * @public
84 * @returns {Observable} - An empty observable
85 */
86
87 }, {
88 key: "commit",
89 value: function commit() {
90 var _this2 = this;
91
92 return new _rxjs.Observable(function (observer) {
93 _this2._txc.commit().then(function () {
94 observer.complete();
95 })["catch"](function (err) {
96 return observer.error(err);
97 });
98 });
99 }
100 /**
101 * Rolls back the transaction.
102 *
103 * @public
104 * @returns {Observable} - An empty observable
105 */
106
107 }, {
108 key: "rollback",
109 value: function rollback() {
110 var _this3 = this;
111
112 return new _rxjs.Observable(function (observer) {
113 _this3._txc.rollback().then(function () {
114 observer.complete();
115 })["catch"](function (err) {
116 return observer.error(err);
117 });
118 });
119 }
120 }]);
121 return RxTransaction;
122}();
123
124exports["default"] = RxTransaction;
\No newline at end of file