Skip to content

Instantly share code, notes, and snippets.

@agustinustheo
Created October 26, 2020 22:25
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/6b3b781e6ccb4e4350549b0eaed5604a to your computer and use it in GitHub Desktop.
Save agustinustheo/6b3b781e6ccb4e4350549b0eaed5604a to your computer and use it in GitHub Desktop.
Python scripts to create, update and delete in FaunaDB.
def create(collection, data):
try:
serverClient = FaunaClient(secret=os.environ.get("FAUNA_SERVER_SECRET"))
res = serverClient.query(q.create(q.collection(collection), {"data": data}))
res["data"]["ref_id"] = res["ref"].id()
return res["data"]
except Exception as ex:
raise ex
def update(collection, id, data):
try:
serverClient = FaunaClient(secret=os.environ.get("FAUNA_SERVER_SECRET"))
res = serverClient.query(q.update(q.ref(q.collection(collection), id), {"data": data}))
res["data"]["ref_id"] = res["ref"].id()
return res["data"]
except Exception as ex:
raise ex
def delete(collection, id):
try:
serverClient = FaunaClient(secret=os.environ.get("FAUNA_SERVER_SECRET"))
serverClient.query(q.delete(q.ref(q.collection(collection), id)))
return True
except Exception as ex:
raise ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment