Skip to content

Commit faa083a

Browse files
committed
implementing more than 30 technologies
1 parent f821101 commit faa083a

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

functions/adoption/libs/queries.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
import os
2-
import json
32
from google.cloud import firestore
3+
from google.cloud.firestore_v1.base_query import FieldFilter
44
from .result import Result
55
from .utils import convert_to_array
66

77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
8+
TABLE = 'adoption'
89

910
def list_data(params):
10-
ref = DB.collection(u'adoption')
1111

12-
query = ref
12+
technology_array = convert_to_array(params['technology'])
13+
data = []
1314

14-
if 'start' in params:
15-
query = query.where('date', '>=', params['start'])
16-
if 'end' in params:
17-
query = query.where('date', '<=', params['end'])
18-
if 'geo' in params:
19-
query = query.where('geo', '==', params['geo'])
20-
if 'technology' in params:
21-
params_array = convert_to_array(params['technology'])
22-
query = query.where('technology', 'in', params_array)
23-
if 'rank' in params:
24-
query = query.where('rank', '==', params['rank'])
15+
for technology in technology_array:
16+
query = DB.collection(TABLE)
2517

26-
documents = query.stream()
18+
if 'start' in params:
19+
query = query.where(filter=FieldFilter('date', '>=', params['start']))
2720

28-
data = []
29-
for doc in documents:
30-
data.append(doc.to_dict())
21+
if 'end' in params:
22+
query = query.where(filter=FieldFilter('date', '<=', params['end']))
23+
24+
if 'geo' in params:
25+
query = query.where(filter=FieldFilter('geo', '==', params['geo']))
26+
27+
if 'rank' in params:
28+
query = query.where(filter=FieldFilter('rank', '==', params['rank']))
29+
30+
query = query.where(filter=FieldFilter('technology', '==', technology))
31+
32+
documents = query.stream()
33+
34+
for doc in documents:
35+
data.append(doc.to_dict())
3136

32-
return Result(result=data)
37+
return Result(result=data)

0 commit comments

Comments
 (0)