Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- New #379: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
- Chg #382: Remove `yiisoft/json` dependency (@Tigrov)
- Enh #384: Refactor according changes in `db` package (@Tigrov)
- New #383: Add `caseSensitive` option to like condition (@vjik)

## 1.2.0 March 21, 2024
Expand Down
2 changes: 1 addition & 1 deletion src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function buildComment(ColumnInterface $column): string
{
$comment = $column->getComment();

return $comment === null ? '' : ' COMMENT ' . $this->queryBuilder->quoter()->quoteValue($comment);
return $comment === null ? '' : ' COMMENT ' . $this->queryBuilder->getQuoter()->quoteValue($comment);
}

protected function getDbType(ColumnInterface $column): string
Expand Down
25 changes: 10 additions & 15 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Throwable;
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\Mysql\Column\ColumnFactory;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -63,30 +65,23 @@ public function createTransaction(): TransactionInterface
return new Transaction($this);
}

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

public function getQueryBuilder(): QueryBuilderInterface
{
return $this->queryBuilder ??= new QueryBuilder(
$this->getQuoter(),
$this->getSchema(),
$this->getServerInfo(),
);
return $this->queryBuilder ??= new QueryBuilder($this);
}

public function getQuoter(): QuoterInterface
{
if ($this->quoter === null) {
$this->quoter = new Quoter('`', '`', $this->getTablePrefix());
}

return $this->quoter;
return $this->quoter ??= new Quoter('`', '`', $this->getTablePrefix());
}

public function getSchema(): SchemaInterface
{
if ($this->schema === null) {
$this->schema = new Schema($this, $this->schemaCache);
}

return $this->schema;
return $this->schema ??= new Schema($this, $this->schemaCache);
}
}
13 changes: 6 additions & 7 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@

namespace Yiisoft\Db\Mysql;

use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

/**
* Implements MySQL, MariaDB specific query builder.
*/
final class QueryBuilder extends AbstractQueryBuilder
{
public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
public function __construct(ConnectionInterface $db)
{
$quoter = $db->getQuoter();
$schema = $db->getSchema();

parent::__construct(
$quoter,
$schema,
$serverInfo,
$db,
new DDLQueryBuilder($this, $quoter, $schema),
new DMLQueryBuilder($this, $quoter, $schema),
new DQLQueryBuilder($this, $quoter),
Expand Down
9 changes: 1 addition & 8 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Mysql\Column\ColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;

Expand Down Expand Up @@ -73,11 +71,6 @@
*/
final class Schema extends AbstractPdoSchema
{
public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

/**
* Returns all unique indexes for the given table.
*
Expand Down Expand Up @@ -405,7 +398,7 @@ private function loadColumn(array $info): ColumnInterface
{
$extra = trim(str_ireplace('auto_increment', '', $info['extra'], $autoIncrement));

$column = $this->getColumnFactory()->fromDefinition($info['column_type'], [
$column = $this->db->getColumnFactory()->fromDefinition($info['column_type'], [
'autoIncrement' => $autoIncrement > 0,
'comment' => $info['column_comment'],
'defaultValueRaw' => $info['column_default'],
Expand Down
2 changes: 1 addition & 1 deletion tests/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testFromTypeDefaultValueRaw(string $type, string|null $defaultVa
public function testExpressionDefaultValueRaw(): void
{
$db = $this->getConnection();
$columnFactory = $db->getSchema()->getColumnFactory();
$columnFactory = $db->getColumnFactory();

$column = $columnFactory->fromType(ColumnType::DATETIME, ['defaultValueRaw' => 'now()', 'extra' => 'DEFAULT_GENERATED']);

Expand Down
10 changes: 10 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Db\Exception\IntegrityException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mysql\Column\ColumnFactory;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -158,4 +159,13 @@ public function testNotRestartConnectionOnTimeoutInTransaction(): void

$db->close();
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());

$db->close();
}
}
10 changes: 0 additions & 10 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Mysql\Column\ColumnBuilder;
use Yiisoft\Db\Mysql\Column\ColumnFactory;
use Yiisoft\Db\Mysql\Schema;
use Yiisoft\Db\Mysql\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
Expand Down Expand Up @@ -493,13 +492,4 @@ public function testInsertDefaultValues()

$db->close();
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getSchema()->getColumnFactory());

$db->close();
}
}
Loading