Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove dependency on BaseConnection in TableName #9104

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function showDataOfTable(string $tableName, int $limitRows, int $limitFi
CLI::newLine();

$this->removeDBPrefix();
$thead = $this->db->getFieldNames(TableName::fromActualName($this->db, $tableName));
$thead = $this->db->getFieldNames(TableName::fromActualName($this->db->DBPrefix, $tableName));
$this->restoreDBPrefix();

// If there is a field named `id`, sort by it.
Expand Down Expand Up @@ -278,7 +278,7 @@ private function makeTableRows(
$this->tbody = [];

$this->removeDBPrefix();
$builder = $this->db->table(TableName::fromActualName($this->db, $tableName));
$builder = $this->db->table(TableName::fromActualName($this->db->DBPrefix, $tableName));
$builder->limit($limitRows);
if ($sortField !== null) {
$builder->orderBy($sortField, $this->sortDesc ? 'DESC' : 'ASC');
Expand Down
12 changes: 6 additions & 6 deletions system/Database/TableName.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ protected function __construct(
* @param string $table Table name (w/o DB prefix)
* @param string $alias Alias name
*/
public static function create(BaseConnection $db, string $table, string $alias = ''): self
public static function create(string $dbPrefix, string $table, string $alias = ''): self
{
return new self(
$db->DBPrefix . $table,
$dbPrefix . $table,
$table,
'',
'',
Expand All @@ -61,9 +61,9 @@ public static function create(BaseConnection $db, string $table, string $alias =
* @param string $actualTable Actual table name with DB prefix
* @param string $alias Alias name
*/
public static function fromActualName(BaseConnection $db, string $actualTable, string $alias = ''): self
public static function fromActualName(string $dbPrefix, string $actualTable, string $alias = ''): self
{
$prefix = $db->DBPrefix;
$prefix = $dbPrefix;
$logicalTable = '';

if (str_starts_with($actualTable, $prefix)) {
Expand All @@ -87,14 +87,14 @@ public static function fromActualName(BaseConnection $db, string $actualTable, s
* @param string $alias Alias name
*/
public static function fromFullName(
BaseConnection $db,
string $dbPrefix,
string $table,
string $schema = '',
string $database = '',
string $alias = ''
): self {
return new self(
$db->DBPrefix . $table,
$dbPrefix . $table,
$table,
$schema,
$database,
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Builder/AliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testAlias(): void

public function testTableName(): void
{
$tableName = TableName::create($this->db, 'jobs', 'j');
$tableName = TableName::create($this->db->DBPrefix, 'jobs', 'j');
$builder = $this->db->table($tableName);

$expectedSQL = 'SELECT * FROM "jobs" "j"';
Expand Down
14 changes: 7 additions & 7 deletions tests/system/Database/TableNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testInstantiate(): void
{
$table = 'table';

$tableName = TableName::create($this->db, $table);
$tableName = TableName::create($this->db->DBPrefix, $table);

$this->assertInstanceOf(TableName::class, $tableName);
}
Expand All @@ -47,7 +47,7 @@ public function testCreateAndTableName(): void
{
$table = 'table';

$tableName = TableName::create($this->db, $table);
$tableName = TableName::create($this->db->DBPrefix, $table);

$this->assertSame($table, $tableName->getTableName());
$this->assertSame('db_table', $tableName->getActualTableName());
Expand All @@ -57,7 +57,7 @@ public function testFromActualNameAndTableNameWithPrefix(): void
{
$actualTable = 'db_table';

$tableName = TableName::fromActualName($this->db, $actualTable);
$tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable);

$this->assertSame('table', $tableName->getTableName());
$this->assertSame($actualTable, $tableName->getActualTableName());
Expand All @@ -67,7 +67,7 @@ public function testFromActualNameAndTableNameWithoutPrefix(): void
{
$actualTable = 'table';

$tableName = TableName::fromActualName($this->db, $actualTable);
$tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable);

$this->assertSame('', $tableName->getTableName());
$this->assertSame($actualTable, $tableName->getActualTableName());
Expand All @@ -78,7 +78,7 @@ public function testGetAlias(): void
$table = 'table';
$alias = 't';

$tableName = TableName::create($this->db, $table, $alias);
$tableName = TableName::create($this->db->DBPrefix, $table, $alias);

$this->assertSame($alias, $tableName->getAlias());
}
Expand All @@ -89,7 +89,7 @@ public function testGetSchema(): void
$schema = 'dbo';
$database = 'test';

$tableName = TableName::fromFullName($this->db, $table, $schema, $database);
$tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database);

$this->assertSame($schema, $tableName->getSchema());
}
Expand All @@ -100,7 +100,7 @@ public function testGetDatabase(): void
$schema = 'dbo';
$database = 'test';

$tableName = TableName::fromFullName($this->db, $table, $schema, $database);
$tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database);

$this->assertSame($database, $tableName->getDatabase());
}
Expand Down
Loading