grafeo.Transaction¶
Transaction management.
Methods¶
execute()¶
Execute a query within the transaction.
execute_sparql()¶
Execute a SPARQL query within the transaction.
commit()¶
Commit the transaction.
rollback()¶
Rollback the transaction.
Properties¶
isolation_level¶
The isolation level of this transaction.
is_active¶
Whether the transaction is still active (not yet committed or rolled back).
Context Manager¶
Example¶
# Using context manager
with db.begin_transaction() as tx:
tx.execute("INSERT (:Person {name: 'Alix'})")
tx.execute("INSERT (:Person {name: 'Gus'})")
tx.commit() # Both inserts committed atomically
# Rollback on error
with db.begin_transaction() as tx:
tx.execute("INSERT (:Person {name: 'Harm'})")
tx.rollback() # Changes discarded
# SPARQL transactions
with db.begin_transaction() as tx:
tx.execute_sparql("""
INSERT DATA {
<http://example.org/alix> <http://xmlns.com/foaf/0.1/name> "Alix" .
}
""")
tx.commit()