@@ -65,12 +65,16 @@ Connect to CrateDB instance running on ``localhost``.
6565.. code-block :: python
6666
6767 >> > # Connect using DB API.
68+ >> > from pprint import pp
6869 >> > from crate import client
70+ >> >
71+ >> > query = " SELECT country, mountain, coordinates, height FROM sys.summits ORDER BY country;"
72+ >> >
6973 >> > with client.connect(" localhost:4200" , username = " crate" ) as connection:
70- >> > cursor = connection.cursor()
71- >> > cursor.execute(" SELECT * FROM sys.summits; " )
72- >> > print (cursor.fetchall())
73- >> > cursor.close()
74+ ... cursor = connection.cursor()
75+ ... cursor.execute(query )
76+ ... pp (cursor.fetchall())
77+ ... cursor.close()
7478
7579 Connect to `CrateDB Cloud `_.
7680
@@ -107,11 +111,16 @@ Connect to CrateDB instance running on ``localhost``.
107111.. code-block :: python
108112
109113 >> > # Connect using SQLAlchemy Core.
114+ >> > from pprint import pp
110115 >> > import sqlalchemy as sa
111- >> > engine = sa.create_engine(" crate://localhost:4200" , echo = True )
116+ >> >
117+ >> > dburi = " crate://localhost:4200"
118+ >> > query = " SELECT country, mountain, coordinates, height FROM sys.summits ORDER BY country;"
119+ >> >
120+ >> > engine = sa.create_engine(dburi, echo = True )
112121 >> > with engine.connect() as connection:
113- >> > with connection.execute(sa.text(" SELECT * FROM sys.summits; " )) as cursor :
114- >> > print (cursor .fetchall())
122+ ... with connection.execute(sa.text(query )) as result :
123+ ... pp(result.mappings() .fetchall())
115124
116125 Connect to `CrateDB Cloud `_.
117126
@@ -129,11 +138,15 @@ Load results into `pandas`_ DataFrame.
129138 >> > # Connect using SQLAlchemy Core and pandas.
130139 >> > import pandas as pd
131140 >> > import sqlalchemy as sa
132- >> > engine = sa.create_engine(" crate://localhost:4200" , echo = True )
141+ >> >
142+ >> > dburi = " crate://localhost:4200"
143+ >> > query = " SELECT * FROM sys.summits ORDER BY country;"
144+ >> >
145+ >> > engine = sa.create_engine(dburi, echo = True )
133146 >> > with engine.connect() as connection:
134- >> > df = pd.read_sql(sql = sa.text(" SELECT * FROM sys.summits; " ), con = connection)
135- >> > df.info()
136- >> > print (df)
147+ ... df = pd.read_sql(sql = sa.text(query ), con = connection)
148+ ... df.info()
149+ ... print (df)
137150
138151
139152 Data types
0 commit comments