コード例 #1
0
def _delete_data():
    resources = [q.functions(), q.indexes(), q.collections()]
    delete = lambda res: q.foreach(
        q.lambda_("res", q.delete(q.var("res"))), q.paginate(res)
    )
    delete_queries = [delete(res) for res in resources]

    _execute_with_retries(q.do(*delete_queries))
コード例 #2
0
 def fauna_read_database(self) -> Dict[List[str], Any]:
     """Read from fauna database."""
     try:
         client = self.get_fauna_connection()
         indexes = client.query(q.paginate(q.indexes()))
         return indexes
     except (Exception) as _error:  # pragma: no cover
         raise ValueError("Fauna error - read database.") from _error
コード例 #3
0
from decouple import config
from faunadb import query as q
from faunadb.client import FaunaClient
from faunadb.objects import Ref
from faunadb.errors import BadRequest, NotFound
from faker import Faker
from models import TweetCategoryEnum

tweetCategories = [e.value for e in TweetCategoryEnum]

fake = Faker()

# Initialize the FaunaDB client
FAUNA_SECRET_KEY = config('FAUNA_SECRET_KEY')
client = FaunaClient(secret=FAUNA_SECRET_KEY)
indexes = client.query(q.paginate(q.indexes()))

# Show FaunaDB indexes
# print(indexes)


class User:
    """
        Description:- Helper functions for User model (CRUD)
    """
    def __init__(self):
        self.collection = 'users'

    def register_user(self, data: dict):
        """ CREATE - Register a new user """
        new_user = client.query(