Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from spiral/fix_postgresql_duplicated_queries
Browse files Browse the repository at this point in the history
Fix postgresql duplicated queries
  • Loading branch information
wolfy-j authored Feb 11, 2020
2 parents 7154dc2 + 28bd50a commit f1ca530
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Driver/Postgres/Query/PostgresInsertQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function withDriver(DriverInterface $driver, string $prefix = null): Quer
public function returning(string $column): self
{
$this->returning = $column;

return $this;
}

Expand All @@ -69,7 +70,7 @@ public function run()
$result = $this->driver->query($queryString, $params->getParameters());

try {
if ($this->driver->getPrimaryKey($this->prefix, $this->table) !== null) {
if ($this->getPrimaryKey() !== null) {
return $result->fetchColumn();
}

Expand All @@ -83,20 +84,29 @@ public function run()
* @return array
*/
public function getTokens(): array
{
return [
'table' => $this->table,
'return' => $this->getPrimaryKey(),
'columns' => $this->columns,
'values' => $this->values
];
}

/**
* @return string
*/
private function getPrimaryKey(): ?string
{
$primaryKey = $this->returning;
if ($primaryKey === null && $this->driver !== null && $this->table !== null) {
try {
$primaryKey = $this->driver->getPrimaryKey($this->prefix, $this->table);
} catch (Throwable $e) {
return null;
}
}

return [
'table' => $this->table,
'return' => $primaryKey,
'columns' => $this->columns,
'values' => $this->values
];
return $primaryKey;
}
}

0 comments on commit f1ca530

Please sign in to comment.