Select all nodes, where date is greater then current date and repeat event option is empty I have content type "event". In this content type I have a date field, provided by the Date Recur module. At the result I have range of the dates: Event start and end date. Also Date Recur provides an option to repeat event. I need to select all event nodes where date field is greater then current date and repeat event option is empty or select all nodes, where repeat event option is not empty. 

My code:

$current_time = \Drupal::service('date.formatter')-&gt;format(time(), 'custom', 'Y-m-d\TH:i:s');

$query = $this-&gt;db_connection-&gt;select('node__field_type', 'n_f_type');
$query-&gt;join('node_field_data', 'n_f_data',
  'n_f_data.nid = n_f_type.entity_id AND n_f_data.type = n_f_type.bundle');  

$query-&gt;join('node__field_event_dates', 'n_event_dates',
  'n_event_dates.bundle = n_f_type.bundle AND n_event_dates.entity_id = n_f_type.entity_id');
$query-&gt;fields('n_f_data', ['nid']);
$query-&gt;condition('n_f_type.bundle', 'event');
$query-&gt;condition('n_f_data.status', 1);
$group_and = $query-&gt;andConditionGroup();
$group_and-&gt;condition('n_event_dates.field_event_dates_value', $current_time, '&gt;=');
$group_and-&gt;condition('n_event_dates.field_event_dates_rrule', '', '&lt;&gt;');
$query-&gt;condition($group_and);
$group_or = $query-&gt;orConditionGroup();
$group_or-&gt;condition('n_event_dates.field_event_dates_rrule', '%RRULE%', 'LIKE');
$query-&gt;condition($group_or);
$query-&gt;range(0, 500);
$events = $query-&gt;execute()-&gt;fetchAll();


Please, can anybody help me to build the correct query, because current query returns empty array.

SELECT * FROM table_name.node__field_event_dates where 
((field_event_dates_value &gt;= '2019-07-17T10:00:00') and 
(field_event_dates_rrule is null or field_event_dates_rrule not like 
'%RRULE%')) or (field_event_dates_rrule like '%RRULE%');


Last query works fine;

I need some help to transform the last query via using Drupal and/or conditions.
Right now your rrule condition is a singleton of its "OR" group. You need to add all the other conditions to an "AND" group and place that group as a sibling to the rrule condition in the "OR" group.