Created
October 26, 2020 21:57
-
-
Save agustinustheo/ef2b977822061cd87fb9c464a531b297 to your computer and use it in GitHub Desktop.
Script to get data from FaunaDB by Index. Usually gets singular data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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