public protocol TransactionContext
func submit(_: ChangeRequest) throws -> UpdatedObject
Submit a change request in a transaction. The change will be available immediately inside this
transaction and will be available once the transaction closure is done to everyone outside of
the transaction closure. It throws a
TransactionError if there are errors. Otherwise, return
UpdatedObject to denote whether you inserted, updated or deleted an object.
func abort() -> Bool
Abort the current transaction. This will cause whatever happened inside the current transaction
to rollback immediately, and anything submitted after abort will throw
public extension TransactionContext
func `try`(submit changeRequest: ChangeRequest) -> UpdatedObject?
Convenient method for submit change request.
submit() may throw exceptions, but
not. Rather, it will fatal in case of
TransactionError.objectAlreadyExists. For any other types of
TransactionError, it will simply return nil.
public enum TransactionError: Error
The transaction has been aborted already before submitting the request.
The object already exists. Conflict on either primary keys or unique properties.
We will rollback the whole transaction in case of disk full.
Other types of errors, in these cases, we will simply rollback the whole transaction.