CRM_Utils_SQL - Add "syncInto()" helper
authorTim Otten <totten@civicrm.org>
Thu, 9 Jul 2020 05:52:29 +0000 (22:52 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 9 Jul 2020 06:19:22 +0000 (23:19 -0700)
commit0624cdc58ffbbce9dcdeb521ab362129d645b9be
tree7155eaab58440e749d59aadb74e7cf0a0d1ad360
parentfbf5eca62154026a4546acb249de53afb6ae6b95
CRM_Utils_SQL - Add "syncInto()" helper

This is slightly more sugary variant of "INSERT INTO...SELECT...ON DUPLICATE UPDATE..." which requires
less boilerplate/duplication.

Before
------

```php
CRM_Utils_SQL_Select::from('foo_table')
  ->select(['foo_name', 'foo_value1', 'foo_value2'])
  ->insertInto('bar_table', ['bar_name', 'bar_output1', 'bar_output2'])
  ->onDuplicate(['bar_output1 = foo_value1', 'bar_output2 = foo_value2'])
```

After
------

```php
CRM_Utils_SQL_Select::from('foo_table')
  ->syncInto('bar_table', 'bar_name', [
    'bar_name' => 'foo_name',
    'bar_output1' => 'foo_value1',
    'bar_output2' => 'foo_value1',
  ])
```
CRM/Utils/SQL/Select.php
tests/phpunit/CRM/Utils/SQL/SelectTest.php