mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 06:07:39 +02:00
Connection::update() Support updating multiple tables at once (#316)
This commit is contained in:
committed by
David Grudl
parent
95c424a71d
commit
168971292d
@@ -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);
|
return $this->command()->update('%n', $table)->set($args);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ declare(strict_types=1);
|
|||||||
* @method Dibi\Reflection\Database getDatabaseInfo()
|
* @method Dibi\Reflection\Database getDatabaseInfo()
|
||||||
* @method Dibi\Fluent command()
|
* @method Dibi\Fluent command()
|
||||||
* @method Dibi\Fluent select(...$args)
|
* @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 insert(string $table, array $args)
|
||||||
* @method Dibi\Fluent delete(string $table)
|
* @method Dibi\Fluent delete(string $table)
|
||||||
* @method Dibi\HashMap getSubstitutes()
|
* @method Dibi\HashMap getSubstitutes()
|
||||||
|
@@ -29,3 +29,15 @@ Assert::same(
|
|||||||
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
|
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
|
||||||
(string) $fluent
|
(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
|
||||||
|
);
|
||||||
|
Reference in New Issue
Block a user