Skip to content

Commit c239161

Browse files
[8.x] Add isolation level configuration for Postgres connector (#40767)
* [8.x] Add isolation level configuration for Postgres connector * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent c275cdc commit c239161

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Illuminate/Database/Connectors/PostgresConnector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function connect(array $config)
3333
$this->getDsn($config), $config, $this->getOptions($config)
3434
);
3535

36+
$this->configureIsolationLevel($connection, $config);
37+
3638
$this->configureEncoding($connection, $config);
3739

3840
// Next, we will check to see if a timezone has been specified in this config
@@ -52,6 +54,20 @@ public function connect(array $config)
5254
return $connection;
5355
}
5456

57+
/**
58+
* Set the connection transaction isolation level.
59+
*
60+
* @param \PDO $connection
61+
* @param array $config
62+
* @return void
63+
*/
64+
protected function configureIsolationLevel($connection, array $config)
65+
{
66+
if (isset($config['isolation_level'])) {
67+
$connection->prepare("set session characteristics as transaction isolation level {$config['isolation_level']}")->execute();
68+
}
69+
}
70+
5571
/**
5672
* Set the connection character set and collation.
5773
*

0 commit comments

Comments
 (0)