Skip to content

Instantly share code, notes, and snippets.

@ShanikaNishadhi
Created April 10, 2022 09:20
Show Gist options
  • Save ShanikaNishadhi/04cf8f8b5fe55417cbab74cd4d79336e to your computer and use it in GitHub Desktop.
Save ShanikaNishadhi/04cf8f8b5fe55417cbab74cd4d79336e to your computer and use it in GitHub Desktop.
import os
from dotenv import load_dotenv
from urllib.parse import urlparse
from faunadb import query as faunaquery
from faunadb.client import FaunaClient
try:
# Load environment variable from .env file
load_dotenv()
secret = os.getenv("DB_ACCESS_KEY")
endpoint = os.getenv("DB_ENDPOINT")
database_url = urlparse(endpoint)
# Instantiate the FaunaDB client
client = FaunaClient(
secret=secret,
domain=database_url.hostname,
port=database_url.port,
scheme=database_url.scheme
)
# Create a Collection
query_result = client.query(faunaquery.create_collection({"name": "testCollection"}))
# Print the Result of the Query
print(f"FaunaDB Collection Creation: \n {query_result}")
except Exception as error:
print(f"Error occurred : {error}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment