|
17 | 17 | */
|
18 | 18 | final class DMLQueryBuilder extends AbstractDMLQueryBuilder
|
19 | 19 | {
|
20 |
| - public function insertWithReturningPks(string $table, QueryInterface|array $columns, array &$params = []): string |
| 20 | + public function insertWithReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string |
21 | 21 | {
|
22 | 22 | $sql = $this->insert($table, $columns, $params);
|
23 |
| - $returnColumns = $this->schema->getTableSchema($table)?->getPrimaryKey(); |
24 |
| - |
25 |
| - if (!empty($returnColumns)) { |
26 |
| - $returnColumns = array_map($this->quoter->quoteColumnName(...), $returnColumns); |
27 |
| - |
28 |
| - $sql .= ' RETURNING ' . implode(', ', $returnColumns); |
29 |
| - } |
30 | 23 |
|
31 |
| - return $sql; |
| 24 | + return $this->appendReturningPksClause($sql, $table); |
32 | 25 | }
|
33 | 26 |
|
34 | 27 | public function resetSequence(string $table, int|string|null $value = null): string
|
@@ -60,9 +53,9 @@ public function resetSequence(string $table, int|string|null $value = null): str
|
60 | 53 |
|
61 | 54 | public function upsert(
|
62 | 55 | string $table,
|
63 |
| - QueryInterface|array $insertColumns, |
64 |
| - bool|array $updateColumns, |
65 |
| - array &$params = [] |
| 56 | + array|QueryInterface $insertColumns, |
| 57 | + array|bool $updateColumns = true, |
| 58 | + array &$params = [], |
66 | 59 | ): string {
|
67 | 60 | $insertSql = $this->insert($table, $insertColumns, $params);
|
68 | 61 |
|
@@ -93,4 +86,28 @@ public function upsert(
|
93 | 86 | return $insertSql
|
94 | 87 | . ' ON CONFLICT (' . implode(', ', $uniqueNames) . ') DO UPDATE SET ' . implode(', ', $updates);
|
95 | 88 | }
|
| 89 | + |
| 90 | + public function upsertWithReturningPks( |
| 91 | + string $table, |
| 92 | + array|QueryInterface $insertColumns, |
| 93 | + array|bool $updateColumns = true, |
| 94 | + array &$params = [], |
| 95 | + ): string { |
| 96 | + $sql = $this->upsert($table, $insertColumns, $updateColumns, $params); |
| 97 | + |
| 98 | + return $this->appendReturningPksClause($sql, $table); |
| 99 | + } |
| 100 | + |
| 101 | + private function appendReturningPksClause(string $sql, string $table): string |
| 102 | + { |
| 103 | + $returnColumns = $this->schema->getTableSchema($table)?->getPrimaryKey(); |
| 104 | + |
| 105 | + if (!empty($returnColumns)) { |
| 106 | + $returnColumns = array_map($this->quoter->quoteColumnName(...), $returnColumns); |
| 107 | + |
| 108 | + $sql .= ' RETURNING ' . implode(', ', $returnColumns); |
| 109 | + } |
| 110 | + |
| 111 | + return $sql; |
| 112 | + } |
96 | 113 | }
|
0 commit comments