1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

Connection::update() Support updating multiple tables at once (#316)

This commit is contained in:
Dalibor Korpar
2018-09-17 10:39:23 +00:00
committed by David Grudl
parent 95c424a71d
commit 168971292d
3 changed files with 17 additions and 2 deletions

View File

@@ -441,7 +441,10 @@ class Connection implements IConnection
}
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);
}

View File

@@ -28,7 +28,7 @@ declare(strict_types=1);
* @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()

View File

@@ -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
);