Skip to content

Commit

Permalink
Update migrations.rst
Browse files Browse the repository at this point in the history
Update documentation based on the latest code changes

```php
    /**
     * @inheritdoc
     */
    public function getQueryBuilder(string $type): Query
    {
        return match ($type) {
            Query::TYPE_SELECT => $this->getDecoratedConnection()->selectQuery(),
            Query::TYPE_INSERT => $this->getDecoratedConnection()->insertQuery(),
            Query::TYPE_UPDATE => $this->getDecoratedConnection()->updateQuery(),
            Query::TYPE_DELETE => $this->getDecoratedConnection()->deleteQuery(),
            default => throw new InvalidArgumentException(
                'Query type must be one of: `select`, `insert`, `update`, `delete`.'
            )
        };
    }
```

Ref 1: https://github.com/cakephp/phinx/blob/b0f4397dd57eb91bd5369c2770a4f2656a3f993c/src/Phinx/Db/Adapter/PdoAdapter.php#L239-L250
  • Loading branch information
MarwanSalim authored Aug 9, 2024
1 parent b0f4397 commit 61e88e8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/en/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ Phinx provides access to a Query builder object, that you may use to execute com

The Query builder is provided by the `cakephp/database <https://github.com/cakephp/database>`_ project, and should
be easy to work with as it resembles very closely plain SQL. Accesing the query builder is done by calling the
``getQueryBuilder()`` function:
``getQueryBuilder(string $type)`` function. The ``string $type`` options are `'select'`, `'insert'`, `'update'` and `'delete'`:


.. code-block:: php
Expand All @@ -1669,7 +1669,7 @@ be easy to work with as it resembles very closely plain SQL. Accesing the query
*/
public function up()
{
$builder = $this->getQueryBuilder();
$builder = $this->getQueryBuilder('select');
$statement = $builder->select('*')->from('users')->execute();
var_dump($statement->fetchAll());
}
Expand Down Expand Up @@ -1864,7 +1864,7 @@ Creating insert queries is also possible:
.. code-block:: php
<?php
$builder = $this->getQueryBuilder();
$builder = $this->getQueryBuilder('insert');
$builder
->insert(['first_name', 'last_name'])
->into('users')
Expand All @@ -1879,13 +1879,13 @@ For increased performance, you can use another builder object as the values for
<?php
$namesQuery = $this->getQueryBuilder();
$namesQuery = $this->getQueryBuilder('select');
$namesQuery
->select(['fname', 'lname'])
->from('users')
->where(['is_active' => true]);
$builder = $this->getQueryBuilder();
$builder = $this->getQueryBuilder('insert');
$st = $builder
->insert(['first_name', 'last_name'])
->into('names')
Expand All @@ -1911,7 +1911,7 @@ Creating update queries is similar to both inserting and selecting:
.. code-block:: php
<?php
$builder = $this->getQueryBuilder();
$builder = $this->getQueryBuilder('update');
$builder
->update('users')
->set('fname', 'Snow')
Expand All @@ -1927,7 +1927,7 @@ Finally, delete queries:
.. code-block:: php
<?php
$builder = $this->getQueryBuilder();
$builder = $this->getQueryBuilder('delete');
$builder
->delete('users')
->where(['accepted_gdpr' => false])
Expand Down

0 comments on commit 61e88e8

Please sign in to comment.