Skip to content

Commit

Permalink
Add transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
hungnguyenhp committed Apr 2, 2024
1 parent 803a330 commit 33397c1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
interface Environment
{
public const PROJECT_NAME = 'My Database Packages by HungNG';
public const VERSION = '4.0.1';
public const VERSION = '4.0.2';
public const LAST_MODIFIED = '2024-04-02';
public const AUTHOR_NAME = 'Hung Nguyen';
public const AUTHOR_EMAIL = '[email protected]';
Expand Down
63 changes: 63 additions & 0 deletions src/Model/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,69 @@ public function getSelectRaw(): ?bool
return $this->selectRaw;
}

/**
* Function startTransaction
*
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* @return void|null
* @throws \Throwable
*/
public function startTransaction()
{
try {
$connection = $this->db->getConnection($this->dbName);
$connection->beginTransaction();
} catch (Exception $e) {
$this->logger->error(__FUNCTION__, 'Error Message: ' . $e->getMessage());
$this->logger->error(__FUNCTION__, 'Error Trace As String: ' . $e->getTraceAsString());

return null;
}
}

/**
* Function transactionCommit
*
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* @return void|null
* @throws \Throwable
*/
public function transactionCommit()
{
try {
$connection = $this->db->getConnection($this->dbName);
$connection->commit();
} catch (Exception $e) {
$this->logger->error(__FUNCTION__, 'Error Message: ' . $e->getMessage());
$this->logger->error(__FUNCTION__, 'Error Trace As String: ' . $e->getTraceAsString());

return null;
}
}

/**
* Function transactionRollBack
*
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* @return void|null
* @throws \Throwable
*/
public function transactionRollBack()
{
try {
$connection = $this->db->getConnection($this->dbName);
$connection->rollBack();
} catch (Exception $e) {
$this->logger->error(__FUNCTION__, 'Error Message: ' . $e->getMessage());
$this->logger->error(__FUNCTION__, 'Error Trace As String: ' . $e->getTraceAsString());

return null;
}
}

/*************************** DATABASE METHOD ***************************/

/**
Expand Down

0 comments on commit 33397c1

Please sign in to comment.