Skip to content

Commit

Permalink
Merge pull request #18 from PhlegmaticGuy/master
Browse files Browse the repository at this point in the history
Small bug preventing Update queries for PostgresSQL
  • Loading branch information
mindplay-dk committed May 27, 2016
2 parents d89f57f + 0a5f697 commit 64f4748
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/postgres/PostgresDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function insert(Table $into)
*/
public function update(Table $table)
{
return $this->container->create(PostgresUpdateQuery::class, ['root' => $table]);
return $this->container->create(PostgresUpdateQuery::class, ['table' => $table]);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,36 @@ function () {
}
);

test(
'can create UPDATE query for PostgreSQL',
function () {
$db = new PostgresDatabase(new DatabaseContainer());

/** @var SampleSchema $schema */
$schema = $db->getSchema(SampleSchema::class);

$user = $schema->user;

$query = $db->update($user)
->setValue($user->first_name, "Rasmus")
->where("{$user->id} = :id")
->bind("id", 123);

$expected_sql = <<<'SQL'
UPDATE "user"
SET "first_name" = :user_first_name
WHERE "user"."id" = :id
SQL;

sql_eq($query, $expected_sql);

check_params($query, [
'user_first_name' => 'Rasmus',
'id' => 123,
]);
}
);

test(
'can create UPDATE query with alias',
function () {
Expand Down

0 comments on commit 64f4748

Please sign in to comment.