Skip to content

Commit

Permalink
Documentation: Use more specific queries for landing page examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Mar 17, 2023
1 parent d160643 commit be7ac6b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ Connect to CrateDB instance running on ``localhost``.
.. code-block:: python
>>> # Connect using DB API.
>>> from pprint import pp
>>> from crate import client
>>>
>>> query = "SELECT country, mountain, coordinates, height FROM sys.summits ORDER BY country;"
>>>
>>> with client.connect("localhost:4200", username="crate") as connection:
>>> cursor = connection.cursor()
>>> cursor.execute("SELECT * FROM sys.summits;")
>>> print(cursor.fetchall())
>>> cursor.close()
... cursor = connection.cursor()
... cursor.execute(query)
... pp(cursor.fetchall())
... cursor.close()
Connect to `CrateDB Cloud`_.

Expand Down Expand Up @@ -107,11 +111,16 @@ Connect to CrateDB instance running on ``localhost``.
.. code-block:: python
>>> # Connect using SQLAlchemy Core.
>>> from pprint import pp
>>> import sqlalchemy as sa
>>> engine = sa.create_engine("crate://localhost:4200", echo=True)
>>>
>>> dburi = "crate://localhost:4200"
>>> query = "SELECT country, mountain, coordinates, height FROM sys.summits ORDER BY country;"
>>>
>>> engine = sa.create_engine(dburi, echo=True)
>>> with engine.connect() as connection:
>>> with connection.execute(sa.text("SELECT * FROM sys.summits;")) as cursor:
>>> print(cursor.fetchall())
... with connection.execute(sa.text(query)) as result:
... pp(result.mappings().fetchall())
Connect to `CrateDB Cloud`_.

Expand All @@ -129,11 +138,15 @@ Load results into `pandas`_ DataFrame.
>>> # Connect using SQLAlchemy Core and pandas.
>>> import pandas as pd
>>> import sqlalchemy as sa
>>> engine = sa.create_engine("crate://localhost:4200", echo=True)
>>>
>>> dburi = "crate://localhost:4200"
>>> query = "SELECT * FROM sys.summits ORDER BY country;"
>>>
>>> engine = sa.create_engine(dburi, echo=True)
>>> with engine.connect() as connection:
>>> df = pd.read_sql(sql=sa.text("SELECT * FROM sys.summits;"), con=connection)
>>> df.info()
>>> print(df)
... df = pd.read_sql(sql=sa.text(query), con=connection)
... df.info()
... print(df)
Data types
Expand Down

0 comments on commit be7ac6b

Please sign in to comment.