Make TransactionIsolation an interface

Switched the enum to implementing the new interface. e.g., MS SQL has a snapshot isolation level, so best to not be strictly limited to an enum.
This commit is contained in:
Aaron Piotrowski 2022-05-27 09:11:31 -05:00
parent 52a30eeded
commit 4b1402e5fc
No known key found for this signature in database
GPG Key ID: 5B456E6AABA44A63
3 changed files with 43 additions and 25 deletions

View File

@ -9,5 +9,7 @@ interface Link extends Executor
*
* @param TransactionIsolation $isolation Transaction isolation level.
*/
public function beginTransaction(TransactionIsolation $isolation = TransactionIsolation::Committed): Transaction;
public function beginTransaction(
TransactionIsolation $isolation = TransactionIsolationLevel::Committed,
): Transaction;
}

View File

@ -2,30 +2,15 @@
namespace Amp\Sql;
enum TransactionIsolation
interface TransactionIsolation
{
case Uncommitted;
case Committed;
case Repeatable;
case Serializable;
/**
* @return string Human-readable label for the transaction isolation level.
*/
public function getLabel(): string;
public function getLabel(): string
{
return match ($this) {
self::Uncommitted => 'Uncommitted',
self::Committed => 'Committed',
self::Repeatable => 'Repeatable',
self::Serializable => 'Serializable',
};
}
public function toSql(): string
{
return match ($this) {
self::Uncommitted => 'READ UNCOMMITTED',
self::Committed => 'READ COMMITTED',
self::Repeatable => 'REPEATABLE READ',
self::Serializable => 'SERIALIZABLE',
};
}
/**
* @return string SQL to be inserted as the transaction isolation level.
*/
public function toSql(): string;
}

View File

@ -0,0 +1,31 @@
<?php
namespace Amp\Sql;
enum TransactionIsolationLevel implements TransactionIsolation
{
case Uncommitted;
case Committed;
case Repeatable;
case Serializable;
public function getLabel(): string
{
return match ($this) {
self::Uncommitted => 'Uncommitted',
self::Committed => 'Committed',
self::Repeatable => 'Repeatable',
self::Serializable => 'Serializable',
};
}
public function toSql(): string
{
return match ($this) {
self::Uncommitted => 'READ UNCOMMITTED',
self::Committed => 'READ COMMITTED',
self::Repeatable => 'REPEATABLE READ',
self::Serializable => 'SERIALIZABLE',
};
}
}