Skip to content

Commit

Permalink
Refactor Dsn class (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Oct 18, 2024
1 parent d43b696 commit 877127f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- New #318: Realize `ColumnBuilder` class (@Tigrov)
- Enh #320: Update according changes in `ColumnSchemaInterface` (@Tigrov)
- New #322: Add `ColumnDefinitionBuilder` class (@Tigrov)
- Enh #323: Refactor `Dsn` class (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
18 changes: 9 additions & 9 deletions src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/
final class Dsn extends AbstractDsn
{
/**
* @psalm-param string[] $options
*/
public function __construct(private string $driver, private string|null $databaseName = null)
public function __construct(string $driver = 'sqlite', string|null $databaseName = null)
{
parent::__construct($driver, '', $databaseName);
}
Expand All @@ -39,11 +36,14 @@ public function __construct(private string $driver, private string|null $databas
*/
public function asString(): string
{
return match ($this->databaseName) {
'' => $this->driver . ':',
'memory' => $this->driver . '::memory:',
null => $this->driver . ':',
default => $this->driver . ':' . $this->databaseName,
$driver = $this->getDriver();
$databaseName = $this->getDatabaseName();

return match ($databaseName) {
'' => "$driver:",
null => "$driver:",
'memory' => "$driver::memory:",
default => "$driver:$databaseName",
};
}
}

0 comments on commit 877127f

Please sign in to comment.