def query(**kwargs):
    # type: (**Any) -> Dict[str, Any]
    '''
    Queries the alerts database.

    Args:
        **kwargs: Arguments to the API endpoint.
    Content:
        {
            "alerts": List[Dict]: list of dictionaries representing alerts in the database
        }
        Each alert has all of the fields in QUERY_FIELDS.
    '''
    response = build_response()
    args = kwargs
    build_arguments(DEFAULT_QUERY_ARGUMENTS, args, response)

    # Build query
    query = ALERTS_QUERY
    params = [] # type: List[Any]
    has_where = False

    # Add possible where statements
    if args['status'] is not None:
        query += build_where(STATUS_WHERE, has_where)
        params.append(args['status'])
        has_where = True

    if args['performed'] is not None:
        query += build_where(PERFORMED_WHERE, has_where)
        params.append(args['performed'])
        has_where = True

    if args['titles'] is not None:
        query += build_where(build_in(TITLE_IN, len(args['titles'])), has_where)
        params.extend(args['titles'])
        has_where = True

    if args['ldap'] is not None:
        query += build_where(build_in(LDAP_IN, len(args['ldap'])), has_where)
        params.extend(args['ldap'])
        has_where = True

    # Add time bounds
    if args['before'] is not None:
        query += build_where(BEFORE, has_where)
        params.append(args['before'])
        has_where = True
    if args['after'] is not None:
        query += build_where(AFTER, has_where)
        params.append(args['after'])
        has_where = True

    # Add limit
    query += 'ORDER BY event_time DESC\n'
    query += LIMIT
    params.append(args['limit'])

    # Make SQL query
    try:
        raw_results = SQLEngine.execute(query, params)
    except SQLEngineException:
        response['error'] = 'Invalid parameters'
        return response

    results = build_query_dict(ALERTS_FIELDS, raw_results)

    # Convert datetimes to unix time
    for alert in results:
        alert['event_time'] = int(alert['event_time'].strftime('%s'))

    response['content']['alerts'] = results
    response['ok'] = True
    return response
Queries the alerts database.

Args:
**kwargs: Arguments to the API endpoint.
Content:
{
"alerts": List[Dict]: list of dictionaries representing alerts in the database
}
Each alert has all of the fields in QUERY_FIELDS.
frontend/securitybot_api.py