Пример #1
0
def send_keys_to_couch(db, keys):
    """
    Copied from dimagi-utils get_docs. Returns a response for every key.
    """
    url = db.uri + '/_all_docs'
    r = requests.post(url=url,
                      data=json.dumps({'keys': filter(None, keys)}),
                      headers={'content-type': 'application/json'},
                      auth=get_auth(url),
                      params={'include_docs': 'true'})
    return r.json()['rows']
Пример #2
0
def send_keys_to_couch(db, keys):
    """
    Copied from dimagi-utils get_docs. Returns a response for every key.
    """
    url = db.uri + '/_all_docs'
    r = requests.post(url=url,
                      data=json.dumps({'keys': [_f for _f in keys if _f]}),
                      headers={'content-type': 'application/json'},
                      auth=get_auth(url),
                      params={'include_docs': 'true'})
    return r.json()['rows']
Пример #3
0
def send_keys_to_couch(db, keys):
    """
    Copied from dimagi-utils get_docs. Returns a response for every key.
    """
    url = db.uri + "/_all_docs"
    r = requests.post(
        url=url,
        data=json.dumps({"keys": filter(None, keys)}),
        headers={"content-type": "application/json"},
        auth=get_auth(url),
        params={"include_docs": "true"},
    )
    return r.json()["rows"]
Пример #4
0
def get_docs(db, keys):
    payload = json.dumps({'keys': keys})
    url = db.uri + '/_all_docs?include_docs=true'

    r = requests.post(url,
                      data=payload,
                      headers={'content-type': 'application/json'},
                      auth=get_auth(url))

    try:
        return r.json()['rows']
    except KeyError:
        logging.exception('%r has no key %r' % (r.json(), 'rows'))
        raise
Пример #5
0
def get_docs(db, keys, **query_params):
    payload = json.dumps({'keys': filter(None, keys)})
    url = db.uri + '/_all_docs'
    query_params['include_docs'] = True

    query_params = {k: json.dumps(v) for k, v in query_params.items()}
    r = requests.post(url, data=payload,
                      headers={'content-type': 'application/json'},
                      auth=get_auth(url),
                      params=query_params)

    try:
        return [row.get('doc') for row in r.json()['rows'] if row.get('doc')]
    except KeyError:
        logging.exception('%r has no key %r' % (r.json(), 'rows'))
        raise
Пример #6
0
def get_docs(db, keys, **query_params):
    if not keys:
        return []

    payload = json.dumps({'keys': [_f for _f in keys if _f]})
    url = db.uri + '/_all_docs'
    query_params['include_docs'] = True

    query_params = {k: json.dumps(v) for k, v in query_params.items()}
    r = requests.post(url, data=payload,
                      headers={'content-type': 'application/json'},
                      auth=get_auth(url),
                      params=query_params)

    try:
        r.raise_for_status()
        return [row.get('doc') for row in r.json()['rows'] if row.get('doc')]
    except KeyError:
        logging.exception('%r has no key %r' % (r.json(), 'rows'))
        raise
    except (HTTPError, JSONDecodeError) as e:
        raise BulkFetchException(e)