-
-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
type: featureNew feature.New feature.
Description
I have an idea!
Hello, Cycle team!
I've been looking for an ability to write more complex insert queries.
And so far I can't find a way to build a query like this one:
INSERT INTO some_table (`key`, `value`) VALUES (...) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)
As I understand PostgreSQL also has this functionality:
https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
So I believe It would be really great to be able to do something like that:
$this->database()
->insert('some_table')
->columns('key', 'value')
->values([['key_1', 'value_1'], ['key_2', 'value_2']])
->onConflict(new Fragment('value = VALUES(value)')) // or ->onDuplicate(...)
->run();
Because now, I have to write it like:
$rows = [...];
$query = <<<SQL
INSERT INTO `some_table` (`key`, `value`) VALUES $rows ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)
SQL;
$this->database()->getDriver()->execute($query);
Any feedback on this would be appreciated.
rauanmayemir and roxblnfk
Metadata
Metadata
Assignees
Labels
type: featureNew feature.New feature.
Type
Projects
Status
Todo