'Retrieves event_ids and pagination tokens around a given event in a
room.
Args:
room_id (str)
event_id (str)
before_limit (int)
after_limit (int)
Returns:
dict'

def _get_events_around_txn(self, txn, room_id, event_id, before_limit, after_limit):

    results = self._simple_select_one_txn(txn, 'events', keyvalues={'event_id': event_id, 'room_id': room_id}, retcols=['stream_ordering', 'topological_ordering'])
    token = RoomStreamToken(results['topological_ordering'], results['stream_ordering'])
    if isinstance(self.database_engine, Sqlite3Engine):
        query_before = 'SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    topological_ordering    <    ?    UNION    ALL    SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    topological_ordering    =    ?    AND    stream_ordering    <    ?    ORDER    BY    topological_ordering    DESC,    stream_ordering    DESC    LIMIT    ?'
        before_args = (room_id, token.topological, room_id, token.topological, token.stream, before_limit)
        query_after = 'SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    topological_ordering    >    ?    UNION    ALL    SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    topological_ordering    =    ?    AND    stream_ordering    >    ?    ORDER    BY    topological_ordering    ASC,    stream_ordering    ASC    LIMIT    ?'
        after_args = (room_id, token.topological, room_id, token.topological, token.stream, after_limit)
    else:
        query_before = ('SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    %s    ORDER    BY    topological_ordering    DESC,    stream_ordering    DESC    LIMIT    ?' % (upper_bound(token, self.database_engine, inclusive=False),))
        before_args = (room_id, before_limit)
        query_after = ('SELECT    topological_ordering,    stream_ordering,    event_id    FROM    events    WHERE    room_id    =    ?    AND    %s    ORDER    BY    topological_ordering    ASC,    stream_ordering    ASC    LIMIT    ?' % (lower_bound(token, self.database_engine, inclusive=False),))
        after_args = (room_id, after_limit)
    txn.execute(query_before, before_args)
    rows = self.cursor_to_dict(txn)
    events_before = [r['event_id'] for r in rows]
    if rows:
        start_token = str(RoomStreamToken(rows[0]['topological_ordering'], (rows[0]['stream_ordering'] - 1)))
    else:
        start_token = str(RoomStreamToken(token.topological, (token.stream - 1)))
    txn.execute(query_after, after_args)
    rows = self.cursor_to_dict(txn)
    events_after = [r['event_id'] for r in rows]
    if rows:
        end_token = str(RoomStreamToken(rows[(-1)]['topological_ordering'], rows[(-1)]['stream_ordering']))
    else:
        end_token = str(token)
    return {'before': {'event_ids': events_before, 'token': start_token}, 'after': {'event_ids': events_after, 'token': end_token}}
