Skip to content

Commit

Permalink
Improve performance of quoting column names up to 10% using `array_ma…
Browse files Browse the repository at this point in the history
…p()`
  • Loading branch information
Tigrov committed Oct 4, 2023
1 parent 380918d commit 04e6374
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder;

use function array_map;
use function implode;

/**
Expand All @@ -22,11 +23,12 @@ public function insertWithReturningPks(string $table, QueryInterface|array $colu
$returnColumns = $this->schema->getTableSchema($table)?->getPrimaryKey();

if (!empty($returnColumns)) {
$returning = [];
foreach ($returnColumns as $name) {
$returning[] = $this->quoter->quoteColumnName($name);
}
$sql .= ' RETURNING ' . implode(', ', $returning);
$returnColumns = array_map(
[$this->quoter, 'quoteColumnName'],
$returnColumns,
);

$sql .= ' RETURNING ' . implode(', ', $returnColumns);
}

return $sql;
Expand Down

0 comments on commit 04e6374

Please sign in to comment.