Execute a GQL statement within this transaction Args: statement: GQL statement to execute Raises: TransactionError: If transaction is already finished or execution fails Examples: >>> with session.transaction() as tx:
(self, statement: str)
| 66 | raise TransactionError(f"Failed to begin transaction: {e}") |
| 67 | |
| 68 | def execute(self, statement: str) -> None: |
| 69 | """ |
| 70 | Execute a GQL statement within this transaction |
| 71 | |
| 72 | Args: |
| 73 | statement: GQL statement to execute |
| 74 | |
| 75 | Raises: |
| 76 | TransactionError: If transaction is already finished or execution fails |
| 77 | |
| 78 | Examples: |
| 79 | >>> with session.transaction() as tx: |
| 80 | ... tx.execute("INSERT (p:Person {name: 'Alice'})") |
| 81 | ... tx.execute("INSERT (p:Person {name: 'Bob'})") |
| 82 | ... tx.commit() |
| 83 | """ |
| 84 | if self._committed: |
| 85 | raise TransactionError("Transaction already committed") |
| 86 | if self._rolled_back: |
| 87 | raise TransactionError("Transaction already rolled back") |
| 88 | |
| 89 | try: |
| 90 | self._session._db.execute(self._session._session_id, statement) |
| 91 | except Exception as e: |
| 92 | raise TransactionError(f"Execute failed: {e}") |
| 93 | |
| 94 | def query(self, query: str) -> QueryResult: |
| 95 | """ |
no test coverage detected