coldbox-modules / qb

Fluent Query Builder for CFML
https://qb.ortusbooks.com/
MIT License
40 stars 35 forks source link

Upsert deleteUnmatched Should allow expresssion #285

Open jclausen opened 2 months ago

jclausen commented 2 months ago

The deleteUnmatched argument in the upsert function is currently too loose, as the result is a deletion of all rows in the database that don't match the source. Its current implementation is an atomic operation on the entire table.

It should be updated to allow an expression to restrict what gets deleted.

Example:

WHEN NOT MATCHED BY SOURCE AND qb_target.foo = 'bar' AND qb_target.active = 1 THEN DELETE

Suggest that the right hand side should allow an expression. Of note is the fact that qb_src cannot be referenced in the WHEN NOT MATCHED BY SOURCE clause.