Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 Add support for MySQL: ON DUPLICATE KEY UPDATE, PostgreSQL: ON CONFLICT #50

Open
insane-dev opened this issue Feb 14, 2022 · 0 comments
Assignees
Labels
type: feature New feature.

Comments

@insane-dev
Copy link

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.

@insane-dev insane-dev added the type: feature New feature. label Feb 14, 2022
@roxblnfk roxblnfk added this to Cycle Feb 22, 2022
@roxblnfk roxblnfk moved this to Backlog in Cycle Feb 22, 2022
@roxblnfk roxblnfk moved this from Backlog to Todo in Cycle Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature.
Projects
Status: Todo
Development

No branches or pull requests

2 participants