Ajout du backend
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
class FirestoreStore:
|
||||
def __init__(self, project_id, collection="measures"):
|
||||
from google.cloud import firestore # import tardif : optionnel
|
||||
|
||||
self.db = firestore.Client(project=project_id)
|
||||
self.collection = collection
|
||||
|
||||
def add_measure(self, measure):
|
||||
self.db.collection(self.collection).add(measure)
|
||||
|
||||
def list_measures(self, device_id, limit=50):
|
||||
docs = (
|
||||
self.db.collection(self.collection)
|
||||
.where("device_id", "==", device_id)
|
||||
.limit(limit)
|
||||
.stream()
|
||||
)
|
||||
return [d.to_dict() for d in docs]
|
||||
Reference in New Issue
Block a user