def find(id=None):
    query = {"selector": {"type": dtype}}
    if id:
        query["selector"]["_id"] = id.split(":")[0]
    ret = rest.whisk_invoke("%s/exec-query-find" % db, {"query": query})
    for rec in ret["docs"]:
        rec["id"] = "%s:%s" % (rec["_id"], rec["_rev"])
    return ret
def insert(args, id=None):
    doc = args.copy()
    doc["type"] = dtype
    if id:
        doc["_id"] = id
    ret = rest.whisk_invoke("%s/create-document" % db, {"doc": doc})
    if "ok" in ret:
        return "%s:%s" % (ret["id"], ret["rev"])
    return None
def delete(id):
    a = id.split(":")
    if len(a) == 1:
        res = find(id)
        if res["docs"]:
            a = res["docs"][0]["id"].split(":")
        else:
            return {"error": "not found"}
    params = {"docid": a[0], "docrev": a[1]}
    ret = rest.whisk_invoke("%s/delete-document" % db, params)
    return ret
def update(args):
    doc = args.copy()
    a = doc["id"].split(":")
    del doc["id"]
    doc["_id"] = a[0]
    doc["_rev"] = a[1]
    doc["type"] = dtype
    ret = rest.whisk_invoke("%s/update-document" % db, {"doc": doc})
    if "ok" in ret:
        return "%s:%s" % (ret["id"], ret["rev"])
    return None
예제 #5
0
def insert(args, id=None):
    doc = args.copy()
    doc["type"] = dtype
    if id:
        doc["_id"] = id
    ret = rest.whisk_invoke("%s/create-document" % db, {"doc": doc})
    global last_error
    if "ok" in ret:
        last_error = None
        return "%s:%s" % (ret["id"], ret["rev"])
    if "error" in ret:
        last_error = ret["error"]["message"]
    return None
예제 #6
0
def update(args):
    doc = args.copy()
    a = doc["id"].split(":")
    del doc["id"]
    doc["_id"] = a[0]
    doc["_rev"] = a[1]
    doc["type"] = dtype
    ret = rest.whisk_invoke("%s/update-document" % db, {"doc": doc})
    global last_error
    if "ok" in ret:
        last_error = None
        return "%s:%s" % (ret["id"], ret["rev"])
    if "error" in ret:
        last_error = ret["error"]["message"]
    return None
예제 #7
0
def find(id=None, bookmark=None):
    query = {
        "selector": {
            "type": dtype
        },
        "sort": [{
            "name": "asc"
        }],
        "limit": find_limit
    }
    if bookmark:
        query["bookmark"] = bookmark
    if id:
        query["selector"]["_id"] = id.split(":")[0]
    ret = rest.whisk_invoke("%s/exec-query-find" % db, {"query": query})
    if "docs" in ret:
        for rec in ret["docs"]:
            rec["id"] = "%s:%s" % (rec["_id"], rec["_rev"])
    return ret