Skip to content

Commit 9d8449c

Browse files
authored
feat(database): display sqlite path in about command (#1353)
1 parent ebde2c6 commit 9d8449c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/database/src/DatabaseInsightsProvider.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
use Tempest\Support\Arr;
1212
use Tempest\Support\Regex;
1313

14+
use function Tempest\root_path;
15+
use function Tempest\Support\Path\normalize;
16+
use function Tempest\Support\Path\to_relative_path;
17+
1418
final class DatabaseInsightsProvider implements InsightsProvider
1519
{
1620
public string $name = 'Database';
@@ -22,10 +26,11 @@ public function __construct(
2226

2327
public function getInsights(): array
2428
{
25-
return [
29+
return array_filter([
2630
'Engine' => $this->getDatabaseEngine(),
2731
'Version' => $this->getDatabaseVersion(),
28-
];
32+
'Path' => $this->getSQLitePath(),
33+
]);
2934
}
3035

3136
private function getDatabaseEngine(): string
@@ -62,4 +67,13 @@ private function getDatabaseVersion(): Insight
6267
return new Insight('Unavailable', Insight::ERROR);
6368
}
6469
}
70+
71+
private function getSQLitePath(): null|Insight|string
72+
{
73+
if (! ($this->databaseConfig instanceof SQLiteConfig)) {
74+
return null;
75+
}
76+
77+
return to_relative_path(getcwd(), normalize($this->databaseConfig->path));
78+
}
6579
}

packages/database/tests/DatabaseInsightsProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function provide_database_drivers(): Generator
3838
yield 'sqlite' => [
3939
new SQLiteConfig(),
4040
'3.45.2',
41-
['Engine' => 'SQLite', 'Version' => new Insight('3.45.2')],
41+
['Engine' => 'SQLite', 'Version' => new Insight('3.45.2'), 'Path' => 'localhost'],
4242
];
4343
yield 'mysql (simple)' => [
4444
new MysqlConfig(),

0 commit comments

Comments
 (0)