Skip to content

Commit b9ad224

Browse files
committed
ops
1 parent 890e1eb commit b9ad224

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/core/src/session.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ class Session {
448448
return this._transactionExecutor.execute(
449449
() => this._beginTransaction(accessMode, transactionConfig),
450450
transactionWork,
451-
tx => new ManagedTransaction({
452-
run: tx.run.bind(tx),
453-
})
451+
ManagedTransaction.fromTransaction
454452
)
455453
}
456454

packages/core/src/transaction-managed.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import Result from './result'
21+
import Transaction from './transaction'
2122
import { Query } from './types'
2223

2324
interface Run {
@@ -32,13 +33,27 @@ interface Run {
3233
class ManagedTransaction {
3334
private _run: Run
3435

35-
constructor({ run }: { run: Run }) {
36+
/**
37+
* @private
38+
*/
39+
private constructor({ run }: { run: Run }) {
3640
/**
3741
* @private
3842
*/
3943
this._run = run
4044
}
4145

46+
/**
47+
* @private
48+
* @param {Transaction} tx - Transaction to wrap
49+
* @returns {ManagedTransaction} the ManagedTransaction
50+
*/
51+
static fromTransaction(tx: Transaction): ManagedTransaction {
52+
return new ManagedTransaction({
53+
run: tx.run.bind(tx)
54+
})
55+
}
56+
4257
/**
4358
* Run Cypher query
4459
* Could be called with a query object i.e.: `{text: "MATCH ...", parameters: {param: 1}}`

packages/core/test/session.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ describe('session', () => {
317317
expect(status.functionCalled).toEqual(true)
318318
expect(run).toHaveBeenCalledWith(query, params)
319319
})
320+
})
320321
})
321322

322323
function mockBeginWithSuccess(connection: FakeConnection) {

packages/neo4j-driver/src/transaction-managed-rx.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,33 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
import RxResult from './result-rx'
20+
import RxTransaction from './transaction-rx'
1921

2022
/**
2123
* Represents a rx transaction that is managed by the transaction executor.
2224
*
2325
* @public
2426
*/
2527
class RxManagedTransaction {
28+
/**
29+
* @private
30+
*/
2631
constructor({ run }) {
2732
this._run = run
2833
}
2934

35+
/**
36+
* @private
37+
* @param {RxTransaction} txc - The transaction to be wrapped
38+
* @returns {RxManagedTransaction} The managed transaction
39+
*/
40+
static fromTransaction (txc) {
41+
return new RxManagedTransaction({
42+
run: txc.run.bind(txc)
43+
})
44+
}
45+
3046
/**
3147
* Creates a reactive result that will execute the query in this transaction, with the provided parameters.
3248
*

0 commit comments

Comments
 (0)