Skip to content

Commit

Permalink
Client Drivers: Improve linking between enumeration list and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 8, 2024
1 parent 04db02c commit f04ca12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ For connecting to CrateDB from Python, supporting Python's `asyncio`.
```
```{sd-item}
[![](https://img.shields.io/github/v/tag/MagicStack/asyncpg?label=latest)](https://github.com/MagicStack/asyncpg)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#python)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#psycopg2)
```
:::

Expand All @@ -333,7 +333,7 @@ For connecting to CrateDB from Python, supporting Python's `asyncio`.
```
```{sd-item}
[![](https://img.shields.io/github/v/tag/psycopg/psycopg?label=latest)](https://github.com/psycopg/psycopg)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#python)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#psycopg3)
```
:::

Expand Down
16 changes: 12 additions & 4 deletions docs/connect/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This guide demonstrates how to connect to a CrateDB Cloud cluster using differen
kinds of Python drivers. Individual drivers offer specific features for specific
needs of your application, so consider reading this enumeration carefully.

.. _crate-python:

crate-python
------------

Expand All @@ -24,10 +26,12 @@ The package can be installed using ``pip install crate[sqlalchemy]``.
with conn:
cursor = conn.cursor()
cursor.execute("SELECT name FROM sys.cluster")
cursor.execute("SELECT * FROM sys.summits")
result = cursor.fetchone()
print(result)
.. _psycopg2:

psycopg2
--------

Expand All @@ -44,10 +48,12 @@ For more information, see the `psycopg documentation`_.
with conn:
with conn.cursor() as cursor:
cursor.execute("SELECT name FROM sys.cluster")
cursor.execute("SELECT * FROM sys.summits")
result = cursor.fetchone()
print(result)
.. _psycopg3:

psycopg3
--------

Expand Down Expand Up @@ -95,13 +101,15 @@ For more information, see the `aiopg documentation`_.
async with aiopg.create_pool(host="<name-of-your-cluster>.cratedb.net", port=5432, user="admin", password="<PASSWORD>", sslmode="require") as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cursor:
await cursor.execute("SELECT name FROM sys.cluster")
await cursor.execute("SELECT * FROM sys.summits")
result = await cursor.fetchone()
print(result)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
.. _asyncpg:

asyncpg
-------

Expand All @@ -118,7 +126,7 @@ For more information, see the `asyncpg documentation`_.
async def run():
conn = await asyncpg.connect(host="<name-of-your-cluster>.cratedb.net", port=5432, user="admin", password="<PASSWORD>", ssl=True)
try:
result = await conn.fetch("SELECT name FROM sys.cluster")
result = await conn.fetch("SELECT * FROM sys.summits")
finally:
await conn.close()
print(result)
Expand Down

0 comments on commit f04ca12

Please sign in to comment.