Skip to content

Commit 63b7b39

Browse files
committed
updated instructions to pass params through QueryOptions instead of query itself
1 parent 7d17dd0 commit 63b7b39

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

tutorial/markdown/python/streamlit/flight_search_streamlit_couchbase.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ def get_routes_for_airports(_connection, selected_airports_df):
183183
airports_faa = str(selected_airports_df["faa"].to_list()) # Initialize a string to store FAA codes in a list format
184184
query = f"""
185185
SELECT * FROM `travel-sample`.`inventory`.`route`
186-
WHERE (sourceairport IN {airports_faa} AND destinationairport IN {airports_faa});
186+
WHERE (sourceairport IN $airports_faa AND destinationairport IN $airports_faa);
187187
"""
188-
result = _connection.query(query)
188+
result = _connection.query(query, opts=QueryOptions(named_parameters={"airports_faa": airports_faa}))
189189
data = []
190190
for row in result:
191191
data.append(row["route"])
@@ -290,16 +290,15 @@ This function retrieves hotel data from the `travel-sample.inventory.hotel` coll
290290
```python
291291
@st.cache_data
292292
def get_all_hotels(_connection, cities):
293-
cities_str = f"{cities}"
294293
query = f"""
295294
SELECT h.*, geo.lat as lat, geo.lon as lon, ARRAY_AVG(ARRAY r.ratings.Overall FOR r IN h.reviews WHEN r.ratings.Overall IS NOT MISSING END) as avg_rating
296295
FROM `travel-sample`.inventory.hotel h
297296
WHERE h.geo.lat IS NOT MISSING
298297
AND h.type = "hotel"
299298
AND h.geo.lon IS NOT MISSING
300-
AND h.city IN {cities_str}
299+
AND h.city IN $cities;
301300
"""
302-
result = _connection.query(query)
301+
result = _connection.query(query, QueryOptions(named_parameters={"cities": cities}))
303302
hotels = []
304303
for row in result:
305304
hotels.append(row)

0 commit comments

Comments
 (0)