forked from couchbaselabs/devguide-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query-placeholders.py
35 lines (26 loc) · 931 Bytes
/
query-placeholders.py
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
33
34
35
#!/usr/bin/env python
from __future__ import print_function
from pprint import pprint
from couchbase.bucket import Bucket
from couchbase.n1ql import N1QLQuery
cb = Bucket('couchbase://10.0.0.31/travel-sample')
def query_city(bkt, city):
query = N1QLQuery('SELECT airportname FROM `travel-sample` '
'WHERE city=$1 AND type="airport"', city)
# Uncomment the following line to make the query optimized for
# repeated invocations.
# The query string is compiled, and the the compiled form is
# stored in the client (as a dictionary value to the query string
# itself).
#
# q.adhoc = False
return bkt.n1ql_query(query)
print('Airports in Reno:')
for row in query_city(cb, 'Reno'):
pprint(row)
print('Airports in Dallas')
for row in query_city(cb, 'Dallas'):
pprint(row)
print('Airports in Los Angeles')
for row in query_city(cb, 'Los Angeles'):
pprint(row)