Skip to content

Commit

Permalink
Merge pull request #25 from funct/quoted_tables
Browse files Browse the repository at this point in the history
Quote table names in shapshot store queries
  • Loading branch information
prolic committed May 16, 2018
2 parents d1d840a + 4b93c1f commit a1faa31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/PdoSnapshotStore.php
Expand Up @@ -49,6 +49,11 @@ final class PdoSnapshotStore implements SnapshotStore
*/
private $disableTransactionHandling;

/**
* @var string
*/
private $vendor;

public function __construct(
PDO $connection,
array $snapshotTableMap = [],
Expand All @@ -61,6 +66,7 @@ public function __construct(
$this->defaultSnapshotTableName = $defaultSnapshotTableName;
$this->serializer = $serializer ?: new CallbackSerializer(null, null);
$this->disableTransactionHandling = $disableTransactionHandling;
$this->vendor = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
}

public function get(string $aggregateType, string $aggregateId): ?Snapshot
Expand Down Expand Up @@ -207,7 +213,12 @@ private function getTableName(string $aggregateType): string
$tableName = $this->defaultSnapshotTableName;
}

return $tableName;
switch ($this->vendor) {
case 'pgsql':
return '"'.$tableName.'"';
default:
return "`$tableName`";
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/PdoSnapshotStoreTest.php
Expand Up @@ -109,6 +109,7 @@ public function it_saves_multiple_snapshots_and_removes_them()
public function it_returns_early_when_no_snapshots_given()
{
$pdo = $this->prophesize(PDO::class);
$pdo->getAttribute(PDO::ATTR_DRIVER_NAME)->willReturn('pgsql'); // Driver does not matter for this test
$pdo->beginTransaction()->shouldNotBeCalled();

$snapshotStore = new PdoSnapshotStore($pdo->reveal());
Expand Down

0 comments on commit a1faa31

Please sign in to comment.