1515use Yiisoft \Db \Exception \NotSupportedException ;
1616use Yiisoft \Db \Query \Data \DataReaderInterface ;
1717use Yiisoft \Db \Query \QueryInterface ;
18+ use Yiisoft \Db \QueryBuilder \DMLQueryBuilderInterface ;
1819use Yiisoft \Db \Schema \Builder \ColumnInterface ;
1920
2021/**
2324 * A command instance is usually created by calling {@see ConnectionInterface::createCommand}.
2425 *
2526 * @psalm-import-type ParamsType from ConnectionInterface
27+ * @psalm-import-type BatchValues from DMLQueryBuilderInterface
2628 */
2729interface CommandInterface
2830{
@@ -156,13 +158,26 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
156158 * For example,
157159 *
158160 * ```php
159- * $connectionInterface->createCommand()->batchInsert (
161+ * $connectionInterface->createCommand()->insertBatch (
160162 * 'user',
161- * ['name', 'age'],
162163 * [
163164 * ['Tom', 30],
164165 * ['Jane', 20],
165166 * ['Linda', 25],
167+ * ],
168+ * ['name', 'age']
169+ * )->execute();
170+ * ```
171+ *
172+ * or as associative arrays where the keys are column names
173+ *
174+ * ```php
175+ * $connectionInterface->createCommand()->insertBatch(
176+ * 'user',
177+ * [
178+ * ['name' => 'Tom', 'age' => 30],
179+ * ['name' => 'Jane', 'age' => 20],
180+ * ['name' => 'Linda', 'age' => 25],
166181 * ]
167182 * )->execute();
168183 * ```
@@ -174,17 +189,17 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
174189 * Also note that the created command isn't executed until {@see execute()} is called.
175190 *
176191 * @param string $table The name of the table to insert new rows into.
177- * @param array $columns The column names.
178192 * @param iterable $rows The rows to be batch inserted into the table.
193+ * @param string[] $columns The column names.
179194 *
180195 * @throws Exception
181196 * @throws InvalidArgumentException
182197 *
183- * @psalm-param iterable<array-key, array<array-key, mixed>> $rows
198+ * @psalm-param BatchValues $rows
184199 *
185200 * Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
186201 */
187- public function batchInsert (string $ table , array $ columns , iterable $ rows ): static ;
202+ public function insertBatch (string $ table , iterable $ rows , array $ columns = [] ): static ;
188203
189204 /**
190205 * Binds a parameter to the SQL statement to be executed.
0 commit comments