Commit the transaction Persists all changes made within this transaction. After calling commit(), the transaction cannot be used further. Raises: TransactionError: If transaction is already finished or commit fails Examples: >>> wit
(self)
| 121 | raise TransactionError(f"Query failed: {e}") |
| 122 | |
| 123 | def commit(self) -> None: |
| 124 | """ |
| 125 | Commit the transaction |
| 126 | |
| 127 | Persists all changes made within this transaction. After calling commit(), |
| 128 | the transaction cannot be used further. |
| 129 | |
| 130 | Raises: |
| 131 | TransactionError: If transaction is already finished or commit fails |
| 132 | |
| 133 | Examples: |
| 134 | >>> with session.transaction() as tx: |
| 135 | ... tx.execute("INSERT (p:Person {name: 'Alice'})") |
| 136 | ... tx.commit() # Changes are now persistent |
| 137 | """ |
| 138 | if self._committed: |
| 139 | raise TransactionError("Transaction already committed") |
| 140 | if self._rolled_back: |
| 141 | raise TransactionError("Transaction already rolled back") |
| 142 | |
| 143 | try: |
| 144 | self._session._db.execute(self._session._session_id, "COMMIT") |
| 145 | self._committed = True |
| 146 | except Exception as e: |
| 147 | raise TransactionError(f"Failed to commit: {e}") |
| 148 | |
| 149 | def rollback(self) -> None: |
| 150 | """ |
no test coverage detected