aiogoldilocks
aiogoldilocks는 GOLDILOCKS 용 비동기 Python 드라이버이다.
pygoldilocks 를 기반으로 하며, aioodbc 구조를 참고하여 asyncio 기반의 안전하고 강력한 비동기 인터페이스를 제공한다.
주요 기능
async/await 기반의 비동기 DB 접근
안전한 커넥션 및 커서 자동 관리 (async with)
커넥션 풀 (create_pool) 지원
사용 예
import asyncio
import aiogoldilocks
async def test_example():
dsn = "DSN=GOLDILOCKS;UID=test;PWD=test"
conn = await aiogoldilocks.connect(dsn=dsn)
cur = await conn.cursor()
await cur.execute("SELECT 42 AS AGE FROM DUAL")
rows = await cur.fetchall()
print(rows)
print(rows[0])
print(rows[0].AGE)
await cur.close()
await conn.close()
asyncio.run(test_example())Connection Pool
import asyncio
import aiogoldilocks
async def test_pool():
dsn = "DSN=GOLDILOCKS;UID=test;PWD=test"
pool = await aiogoldilocks.create_pool(dsn=dsn)
async with pool.acquire() as conn:
cur = await conn.cursor()
await cur.execute("SELECT 42 FROM DUAL")
r = await cur.fetchall()
print(r)
await cur.close()
await conn.close()
pool.close()
await pool.wait_closed()
asyncio.run(test_pool())Context Manager
import asyncio
import aiogoldilocks
async def test_example():
dsn = "DSN=GOLDILOCKS;UID=test;PWD=test"
async with aiogoldilocks.create_pool(dsn=dsn) as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42 AS AGE FROM DUAL")
val = await cur.fetchone()
print(val)
print(val.AGE)
asyncio.run(test_example())설치 방법
$GOLDILOCKS_HOME/app_dev/aiogoldilocks 디렉토리에 다음과 같이 설치한다.
pip install .
설치를 위해서는 GOLDILOCKS 드라이버가 미리 설치되어 있어야 하며, DSN 또는 연결 문자열도 사전에 설정되어 있어야 한다.
요구 사항
Python 3.7 이상
GOLDILOCKS 드라이버 설치
pygoldilocks 버전 26.1.0 이상