Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function to get multiple documents from FaunaDB
def get_multiple(index, data=None):
try:
serverClient = FaunaClient(secret=os.environ.get("FAUNA_SERVER_SECRET"))
res_arr = []
if data is None:
res = serverClient.query(
q.map_(
q.lambda_("data", q.get(q.var("data"))),
q.paginate(q.match(q.index(index)))
)
)
res_arr.extend(res["data"])
elif isinstance(data, list):
for x in data:
res = serverClient.query(
q.map_(
q.lambda_("data", q.get(q.var("data"))),
q.paginate(q.match(q.index(index), q.casefold(x)))
)
)
res_arr.extend(res["data"])
else:
res = serverClient.query(
q.map_(
q.lambda_("data", q.get(q.var("data"))),
q.paginate(q.match(q.index(index), q.casefold(data)))
)
)
res_arr.extend(res["data"])
arr = []
for x in res_arr:
x["data"]["ref_id"] = x["ref"].id()
arr.append(x["data"])
return arr
except Exception as ex:
raise ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment