-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.py
More file actions
32 lines (26 loc) · 782 Bytes
/
firestore.py
File metadata and controls
32 lines (26 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from google.cloud import firestore
def doc_to_dict(doc):
if not doc.exists:
return None
doc_dict = doc.to_dict()
doc_dict['id'] = doc.id
return doc_dict
def read_all():
db = firestore.Client()
query = db.collection(u'Player')
players = query.stream();
players = list(map(doc_to_dict, players))
return players
def read(id):
db = firestore.Client()
player = db.collection(u'Player').document(id)
return doc_to_dict(player.get())
def update(data, player_id=None):
db = firestore.Client()
player = db.collection(u'Player').document(player_id)
player.set(data)
return doc_to_dict(player.get())
def delete(id):
db = firestore.Client()
player = db.collection(u'Player').document(id)
player.delete()