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

Introduce getQueryBuilder aliases for specific database actions #2242

Merged
merged 7 commits into from
Dec 4, 2023
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
32 changes: 32 additions & 0 deletions src/Phinx/Db/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace Phinx\Db\Adapter;

use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Table;
use Phinx\Migration\MigrationInterface;
Expand Down Expand Up @@ -287,6 +291,34 @@ public function executeActions(Table $table, array $actions): void;
*/
public function getQueryBuilder(string $type): Query;

/**
* Return a new SelectQuery object
*
* @return \Cake\Database\Query\SelectQuery
*/
public function getSelectBuilder(): SelectQuery;

/**
* Return a new InsertQuery object
*
* @return \Cake\Database\Query\InsertQuery
*/
public function getInsertBuilder(): InsertQuery;

/**
* Return a new UpdateQuery object
*
* @return \Cake\Database\Query\UpdateQuery
*/
public function getUpdateBuilder(): UpdateQuery;

/**
* Return a new DeleteQuery object
*
* @return \Cake\Database\Query\DeleteQuery
*/
public function getDeleteBuilder(): DeleteQuery;

/**
* Executes a SQL statement.
*
Expand Down
36 changes: 36 additions & 0 deletions src/Phinx/Db/Adapter/AdapterWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace Phinx\Db\Adapter;

use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use PDO;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Table;
Expand Down Expand Up @@ -485,4 +489,36 @@ public function getQueryBuilder(string $type): Query
{
return $this->getAdapter()->getQueryBuilder($type);
}

/**
* @inheritDoc
*/
public function getSelectBuilder(): SelectQuery
{
return $this->getAdapter()->getSelectBuilder();
}

/**
* @inheritDoc
*/
public function getInsertBuilder(): InsertQuery
{
return $this->getAdapter()->getInsertBuilder();
}

/**
* @inheritDoc
*/
public function getUpdateBuilder(): UpdateQuery
{
return $this->getAdapter()->getUpdateBuilder();
}

/**
* @inheritDoc
*/
public function getDeleteBuilder(): DeleteQuery
{
return $this->getAdapter()->getDeleteBuilder();
}
}
36 changes: 36 additions & 0 deletions src/Phinx/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use BadMethodCallException;
use Cake\Database\Connection;
use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use InvalidArgumentException;
use PDO;
use PDOException;
Expand Down Expand Up @@ -244,6 +248,38 @@ public function getQueryBuilder(string $type): Query
};
}

/**
* @inheritDoc
*/
public function getSelectBuilder(): SelectQuery
{
return $this->getDecoratedConnection()->selectQuery();
}

/**
* @inheritDoc
*/
public function getInsertBuilder(): InsertQuery
{
return $this->getDecoratedConnection()->insertQuery();
}

/**
* @inheritDoc
*/
public function getUpdateBuilder(): UpdateQuery
{
return $this->getDecoratedConnection()->updateQuery();
}

/**
* @inheritDoc
*/
public function getDeleteBuilder(): DeleteQuery
{
return $this->getDecoratedConnection()->deleteQuery();
}

/**
* Executes a query and returns PDOStatement.
*
Expand Down
36 changes: 36 additions & 0 deletions src/Phinx/Migration/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace Phinx\Migration;

use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use RuntimeException;
Expand Down Expand Up @@ -214,6 +218,38 @@ public function getQueryBuilder(string $type): Query
return $this->getAdapter()->getQueryBuilder($type);
}

/**
* @inheritDoc
*/
public function getSelectBuilder(): SelectQuery
{
return $this->getAdapter()->getSelectBuilder();
}

/**
* @inheritDoc
*/
public function getInsertBuilder(): InsertQuery
{
return $this->getAdapter()->getInsertBuilder();
}

/**
* @inheritDoc
*/
public function getUpdateBuilder(): UpdateQuery
{
return $this->getAdapter()->getUpdateBuilder();
}

/**
* @inheritDoc
*/
public function getDeleteBuilder(): DeleteQuery
{
return $this->getAdapter()->getDeleteBuilder();
}

/**
* @inheritDoc
*/
Expand Down
48 changes: 48 additions & 0 deletions src/Phinx/Migration/MigrationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
namespace Phinx\Migration;

use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -165,6 +169,50 @@ public function query(string $sql, array $params = []): mixed;
*/
public function getQueryBuilder(string $type): Query;

/**
* Returns a new SelectQuery object that can be used to build complex
* SELECT queries and execute them against the current database.
*
* Queries executed through the query builder are always sent to the database, regardless of the
* the dry-run settings.
*
* @return \Cake\Database\Query\SelectQuery
*/
public function getSelectBuilder(): SelectQuery;

/**
* Returns a new InsertQuery object that can be used to build complex
* INSERT queries and execute them against the current database.
*
* Queries executed through the query builder are always sent to the database, regardless of the
* the dry-run settings.
*
* @return \Cake\Database\Query\InsertQuery
*/
public function getInsertBuilder(): InsertQuery;

/**
* Returns a new UpdateQuery object that can be used to build complex
* UPDATE queries and execute them against the current database.
*
* Queries executed through the query builder are always sent to the database, regardless of the
* the dry-run settings.
*
* @return \Cake\Database\Query\UpdateQuery
*/
public function getUpdateBuilder(): UpdateQuery;

/**
* Returns a new DeleteQuery object that can be used to build complex
* DELETE queries and execute them against the current database.
*
* Queries executed through the query builder are always sent to the database, regardless of the
* the dry-run settings.
*
* @return \Cake\Database\Query\DeleteQuery
*/
public function getDeleteBuilder(): DeleteQuery;

/**
* Executes a query and returns only one row as an array.
*
Expand Down
Loading