Skip to content

Commit

Permalink
Connection::update() Support updating multiple tables at once (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakorpar authored and dg committed Sep 17, 2018
1 parent 95c424a commit 1689712
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Dibi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ public function select(...$args): Fluent
}


public function update(string $table, iterable $args): Fluent
/**
* @param string|string[] $table
*/
public function update($table, iterable $args): Fluent
{
return $this->command()->update('%n', $table)->set($args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/dibi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @method Dibi\Reflection\Database getDatabaseInfo()
* @method Dibi\Fluent command()
* @method Dibi\Fluent select(...$args)
* @method Dibi\Fluent update(string $table, array $args)
* @method Dibi\Fluent update(string|string[] $table, array $args)
* @method Dibi\Fluent insert(string $table, array $args)
* @method Dibi\Fluent delete(string $table)
* @method Dibi\HashMap getSubstitutes()
Expand Down
12 changes: 12 additions & 0 deletions tests/dibi/Fluent.update.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ Assert::same(
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
(string) $fluent
);


$arr = [
'table1.title' => 'Super Product',
'table2.price' => 12,
'table2.brand' => null,
];
$fluent = $conn->update(['table1', 'table2'], $arr);
Assert::same(
reformat('UPDATE [table1], [table2] SET [table1].[title]=\'Super Product\', [table2].[price]=12, [table2].[brand]=NULL'),
(string) $fluent
);

0 comments on commit 1689712

Please sign in to comment.