Skip to content

Instantly share code, notes, and snippets.

@agustinustheo
Created October 26, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustinustheo/ef2b977822061cd87fb9c464a531b297 to your computer and use it in GitHub Desktop.
Save agustinustheo/ef2b977822061cd87fb9c464a531b297 to your computer and use it in GitHub Desktop.
Script to get data from FaunaDB by Index. Usually gets singular data.
import os
from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient
def get(index, data):
try:
serverClient = FaunaClient(secret=os.environ.get("FAUNA_SERVER_SECRET"))
res = serverClient.query(q.get(q.match(q.index(index), data)))
res["data"]["ref_id"] = res["ref"].id()
return res["data"]
except Exception as ex:
raise ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment