Home Reference Source

lib6/transaction-managed.js

  1. /**
  2. * Copyright (c) "Neo4j"
  3. * Neo4j Sweden AB [https://neo4j.com]
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * Represents a transaction that is managed by the transaction executor.
  19. *
  20. * @public
  21. */
  22. class ManagedTransaction {
  23. /**
  24. * @private
  25. */
  26. constructor({ run }) {
  27. /**
  28. * @private
  29. */
  30. this._run = run;
  31. }
  32. /**
  33. * @private
  34. * @param {Transaction} tx - Transaction to wrap
  35. * @returns {ManagedTransaction} the ManagedTransaction
  36. */
  37. static fromTransaction(tx) {
  38. return new ManagedTransaction({
  39. run: tx.run.bind(tx)
  40. });
  41. }
  42. /**
  43. * Run Cypher query
  44. * Could be called with a query object i.e.: `{text: "MATCH ...", parameters: {param: 1}}`
  45. * or with the query and parameters as separate arguments.
  46. * @param {mixed} query - Cypher query to execute
  47. * @param {Object} parameters - Map with parameters to use in query
  48. * @return {Result} New Result
  49. */
  50. run(query, parameters) {
  51. return this._run(query, parameters);
  52. }
  53. }
  54. export default ManagedTransaction;