From 61e88e847927454a58a027fb64eff6aaf3c03d48 Mon Sep 17 00:00:00 2001 From: Marwan Salim <45453458+MarwanSalim@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:51:06 +0800 Subject: [PATCH] Update migrations.rst 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 --- docs/en/migrations.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/migrations.rst b/docs/en/migrations.rst index aa4006b2d..25fbd0d06 100644 --- a/docs/en/migrations.rst +++ b/docs/en/migrations.rst @@ -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 `_ 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 @@ -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()); } @@ -1864,7 +1864,7 @@ Creating insert queries is also possible: .. code-block:: php getQueryBuilder(); + $builder = $this->getQueryBuilder('insert'); $builder ->insert(['first_name', 'last_name']) ->into('users') @@ -1879,13 +1879,13 @@ For increased performance, you can use another builder object as the values for 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') @@ -1911,7 +1911,7 @@ Creating update queries is similar to both inserting and selecting: .. code-block:: php getQueryBuilder(); + $builder = $this->getQueryBuilder('update'); $builder ->update('users') ->set('fname', 'Snow') @@ -1927,7 +1927,7 @@ Finally, delete queries: .. code-block:: php getQueryBuilder(); + $builder = $this->getQueryBuilder('delete'); $builder ->delete('users') ->where(['accepted_gdpr' => false])