|
| 1 | +# Notice |
| 2 | + |
| 3 | +**This component is a Preview feature provided for experimental purposes only. |
| 4 | +It is provided "AS IS" and without warranty of any kind. This module is not |
| 5 | +supported by Snowflake Support. Use of this code is at your own risk and it |
| 6 | +is not intended for production environments.** |
| 7 | + |
| 8 | +## Features NOT Supported |
| 9 | + |
| 10 | + |
| 11 | +- ❌ `conn.errorhandler` (get/set) - no support for async errorhandlers |
| 12 | +- ❌ `enable_connection_diag=True` - no connection diagnostic |
| 13 | +- ❌ `authenticator='PAT_WITH_EXTERNAL_SESSION'` - not supported |
| 14 | +- ❌ `mfa_callback` / `password_callback` - not supported |
| 15 | +- ❌ `_probe_connection=True` - no connection diagnostic |
| 16 | +- ❌ Raw binary response handling - not supported |
| 17 | +- ❌ CRL (Certificate Revocation List) - not supported (only OCSP is supported) |
| 18 | + |
| 19 | +## Installation & Import |
| 20 | + |
| 21 | +Using aio version requires additional installation of `aiohttp` dependency. |
| 22 | + |
| 23 | +```python |
| 24 | +# Same package, different import |
| 25 | +from snowflake.connector.aio import connect, SnowflakeConnection, DictCursor |
| 26 | +``` |
| 27 | + |
| 28 | + |
| 29 | +## Connection Patterns |
| 30 | + |
| 31 | + |
| 32 | +```python |
| 33 | +# Pattern 1: Async context manager (recommended) |
| 34 | +async with connect(user='...', password='...', account='...') as conn: |
| 35 | + # Use connection |
| 36 | + pass |
| 37 | + |
| 38 | + |
| 39 | +# Pattern 2: Direct await |
| 40 | +conn = await connect(user='...', password='...', account='...') |
| 41 | +await conn.close() |
| 42 | + |
| 43 | + |
| 44 | +# Pattern 3: Manual |
| 45 | +conn = SnowflakeConnection(user='...', password='...', account='...') |
| 46 | +await conn.connect() |
| 47 | +await conn.close() |
| 48 | +``` |
| 49 | + |
| 50 | + |
| 51 | +## Basic Operations Comparison |
| 52 | + |
| 53 | + |
| 54 | +| Operation | Sync | Async | |
| 55 | +|-----------|------|-------| |
| 56 | +| **Connect** | `conn = connect(...)` | `conn = await connect(...)` | |
| 57 | +| **Create cursor** | `cur = conn.cursor()` | `cur = conn.cursor()` *(same)* | |
| 58 | +| **Execute** | `cur.execute(sql)` | `await cur.execute(sql)` | |
| 59 | +| **Fetch one** | `cur.fetchone()` | `await cur.fetchone()` | |
| 60 | +| **Fetch many** | `cur.fetchmany(n)` | `await cur.fetchmany(n)` | |
| 61 | +| **Fetch all** | `cur.fetchall()` | `await cur.fetchall()` | |
| 62 | +| **Iterate** | `for row in cur:` | `async for row in cur:` | |
| 63 | +| **Commit** | `conn.commit()` | `await conn.commit()` | |
| 64 | +| **Rollback** | `conn.rollback()` | `await conn.rollback()` | |
| 65 | +| **Close** | `conn.close()` | `await conn.close()` | |
| 66 | + |
| 67 | + |
| 68 | +## Quick Examples |
| 69 | + |
| 70 | + |
| 71 | +### Simple Query |
| 72 | + |
| 73 | + |
| 74 | +```python |
| 75 | +import asyncio |
| 76 | +from snowflake.connector.aio import connect |
| 77 | + |
| 78 | + |
| 79 | +async def query_data(): |
| 80 | + async with connect(user='...', password='...', account='...') as conn: |
| 81 | + async with conn.cursor() as cur: |
| 82 | + await cur.execute("SELECT * FROM table WHERE id < %s", (100,)) |
| 83 | + async for row in cur: |
| 84 | + print(row) |
| 85 | + |
| 86 | + |
| 87 | +asyncio.run(query_data()) |
| 88 | +``` |
0 commit comments