diff --git a/functions/lighthouse/libs/queries.py b/functions/lighthouse/libs/queries.py index 5bd7c96..fee3cc4 100644 --- a/functions/lighthouse/libs/queries.py +++ b/functions/lighthouse/libs/queries.py @@ -1,10 +1,11 @@ import os -import json from google.cloud import firestore +from google.cloud.firestore_v1.base_query import FieldFilter from .result import Result from .utils import convert_to_array DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) +TABLE = 'lighthouse' def list_data(params): @@ -12,16 +13,16 @@ def list_data(params): data = [] for technology in technology_array: - query = DB.collection(u'lighthouse') + query = DB.collection(TABLE) if 'start' in params: - query = query.where('date', '>=', params['start']) + query = query.where(filter=FieldFilter('date', '>=', params['start'])) if 'end' in params: - query = query.where('date', '<=', params['end']) + query = query.where(filter=FieldFilter('date', '<=', params['end'])) - query = query.where('geo', '==', params['geo']) - query = query.where('rank', '==', params['rank']) - query = query.where('technology', '==', technology) + query = query.where(filter=FieldFilter('geo', '==', params['geo'])) + query = query.where(filter=FieldFilter('rank', '==', params['rank'])) + query = query.where(filter=FieldFilter('technology', '==', technology)) documents = query.stream()