8.3 KiB
8.3 KiB
In [1]:
import warnings
warnings.simplefilter(action="ignore", category=FutureWarning)
In [2]:
!pip install couchbase==4.1.1 -q
!pip install pandas==1.5.2 -q
Import the the classes necessary to run the couchbase connector.
In [3]:
import pandas as pd
from couchbase.cluster import Cluster
from couchbase.auth import PasswordAuthenticator
from couchbase.options import ClusterOptions, QueryOptions
Connect to the cluster select the sample bucket and connect to the default collection.
In [4]:
cluster = Cluster.connect(
"couchbase://couchbase1",
ClusterOptions(
PasswordAuthenticator("Administrator", "some-pw-that-is-better-than-this!")
),
)
bucket = cluster.bucket("travel-sample")
# get a reference to the default collection
cb_coll = bucket.default_collection()
Acces a document by key.
In [5]:
# get a document by key
result = cb_coll.get("airline_10")
result.value
Out[5]:
The Querry language contains a If a hyphen is used please use a pair of ` to surround the name using a hyphen.
In [6]:
result = cluster.query(
"""
SELECT airport.*
FROM `travel-sample`.inventory.airport airport
""",
QueryOptions(metrics=True),
)
df = pd.DataFrame(result)
df.info()
In [11]:
result = cluster.query(
"""
SELECT airport.airportname, airport.city, airport.country
FROM `travel-sample`.inventory.airport airport INNER JOIN `travel-sample`.inventory.landmark landmark on airport.city = landmark.city
""",
QueryOptions(metrics=True),
)
print(pd.DataFrame(result).sample(5).to_latex(bold_rows=True))
In [13]:
result = cluster.query(
"""
SELECT airport.airportname, airport.city, airport.country, landmark.name
FROM `travel-sample`.inventory.airport airport INNER JOIN `travel-sample`.inventory.landmark landmark on airport.city = landmark.city
""",
QueryOptions(metrics=True),
)
print(pd.DataFrame(result).sample(5).sort_index().to_latex(bold_rows=True))
End here¶
This should not be shownm