Open SevDan opened 3 years ago
Maybe should implement easier API (adopted for single thread applications)
bool pg_tx_begin(userdata connection)
Creates new transaction only if has no opened other yet
bool pg_tx_commit(userdata connection)
Commit current transaction
bool pg_tx_rollback(userdata connection)
Rollback current transaction
So, API supports operations only one transaction per connection (without subtransactions)
There is good way to implement user transactions
Example API:
userdata pg_begin_tx(userdata connection)
Execute queryCREATE TRANSACTION
, set it status 'open' and save into local transactions storage.userdata pg_rollback_tx(userdata transaction)
Get transaction from storage. If transaction is open and valid, rollback it withROLLBACK
and set 'rollbacked' status. Abort transaction when has no instances in storageuserdata pg_commit_tx(userdata transaction)
Get transaction from storage and commit it withCOMMIT
if opened and set 'commited' status. Abort transaction when has no instances in storageClient database transactions control implementation may prevent problems with concurrent execution and add more performance features (for instance, execute whole transaction in one query)