示例#1
0
 def get_user(self, document):
     doc = db.collection(self.collction).document(document).get()
     if doc.exists:
         print("Duplicate Key Found. {}".format(doc.get('email')))
         return doc.to_dict()
     else:
         return None
示例#2
0
 def create_user(self, model):
     doc = db.collection(self.collction).document(str(model.email)).get()
     if doc.exists:
         print("Duplicate Key Found. {}".format(doc.get('email')))
         return False
     
     doc = self.db.collection(self.collction).document(str(model.email)).set(model.dict())
     if not doc:
         raise("document not saved")
     return True
示例#3
0
 def get_all_users(self):
     docs = db.collection(self.collction).stream()
     users_list = [doc.to_dict() for doc in docs ]
     return users_list
示例#4
0
 def delete_user(self, document):
     doc_ref = db.collection(self.collction).document(document).delete()
     return True
示例#5
0
 def update_user(self, document, data={}):
     print(data)
     doc_ref = db.collection(self.collction).document(document).update(data)
     if not doc_ref:
         raise("document not saved")
     return True
示例#6
0
 def update_article(self, document, model):
     doc_ref = db.collection(self.collction).document(document).update(
         model.dict())
     if not doc_ref:
         raise ("document not saved")
     return True
示例#7
0
 def get_article(self, document):
     doc = db.collection(self.collction).document(document).get()
     if doc.exists:
         return doc.to_dict()
     else:
         raise ("No Details Found")