Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def db_value(self, model):
# check reference model and passing model is same
if not issubclass(model.__class__, self.model_ref):
raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
f'{self.model_ref.__name__}, but got {model.__class__.__name__}')
# Get document reference from firestore
return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
def get_ref(self):
"""Provide firestore ref for model collection"""
# Validate the key
self.validate_key()
if self.group_collection:
return db.conn.collection_group(self.collection_path)
return db.conn.collection(self.collection_path)
def db_value(self, model):
# if no model is provided then return None
if model is None:
return None
# check reference model and passing model is same
if not issubclass(model.__class__, self.model_ref):
raise errors.ReferenceTypeError(f'Invalid reference type. Field "{self.name}" required value type '
f'"{self.model_ref.__name__}", but got "{model.__class__.__name__}"')
# Get document reference from firestore
return firestore.DocumentReference(*utils.ref_path(model.key), client=db.conn)
def get_ref(self):
"""Provide firestore ref for model collection"""
# Validate the key
self.validate_key()
if self.group_collection:
return db.conn.collection_group(self.collection_path)
return db.conn.collection(self.collection_path)
def transaction(**kwargs):
return db.conn.transaction(**kwargs)
def batch():
return db.conn.batch()