mirror of
https://github.com/danog/sql.git
synced 2024-11-26 20:15:08 +01:00
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:
parent
52a30eeded
commit
4b1402e5fc
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
31
src/TransactionIsolationLevel.php
Normal file
31
src/TransactionIsolationLevel.php
Normal 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',
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user