nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
512 stars 108 forks source link

REPLACE AND INSERT ... ON DUPLICATE KEY UPDATE support in Explorer #305

Open tprochazka opened 9 months ago

tprochazka commented 9 months ago

Would be really useful to have

$this->db->table('table')->replace()

It is the same like INSERT, just with REPLACE is used

Or

$this->db->table('table')->inserOrUpdate($newData, $updateData)

Useful when update should for example increment some column, change date, etc.

Reference: https://dev.mysql.com/doc/refman/8.0/en/replace.html https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

diegosardina commented 9 months ago

While I agree it would be nice to have, it's too database-vendor specific.

PostgreSQL:

... ON CONFLICT (column) DO ...

FirebirdSQL:

UPDATE OR INSERT INTO table ... MATCHING (column) ...

Implementing MERGE (that is SQL standard) makes more sense. However it seems that MySQL still doesn't support it.

The best, for now, is an ad-hoc query.