feat(db): Cloudflare D1 + 범용 SQLAlchemy explorer + 자동 라우팅 팩토리#229
Merged
Conversation
회사 DB 연결을 쉽게 — DSN 하나로 라우팅되는 explorer 어댑터 레이어. - adapters/db/d1_explorer.py: Cloudflare D1 ExplorerPort (HTTP Query API, urllib/stdlib). SQLite라 sqlite_master/PRAGMA로 introspection. transport 주입 가능 → 네트워크 없이 테스트. 식별자 검증으로 인젝션 차단. - adapters/db/sqlalchemy_explorer.py: 범용 ExplorerPort. SQLAlchemy URL만 바꾸면 Postgres/BigQuery/Snowflake/MySQL/DuckDB 등 커버. engine lazy 생성(드라이버 미설치여도 라우팅 가능), blocking 호출은 to_thread. - adapters/db/factory.py: build_explorer(conn) — d1:// → D1, 그 외 → SQLAlchemy. explorer_from_env(): LANG2SQL_DB_URL > Cloudflare D1 env > stub fallback. - concierge: 기본 explorer를 explorer_from_env()로(없으면 stub). - pyproject: sqlalchemy core dep + postgres/bigquery/snowflake/mysql/duckdb/ all-db extra. .env.example에 연결 옵션 문서화. - tests/test_db_adapters.py: factory 라우팅, SQLAlchemy 실 sqlite introspection /execute, D1 mock transport(list/describe/execute/error/식별자검증). 검증: 93 테스트 통과(84+9), concierge env 라우팅 3종(SQLAlchemy/stub/D1) 확인. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
무엇
V1의 PG stub explorer 자리를 진짜 외부 DB와 연결되는 어댑터 레이어로 채움. D1은 자체 HTTP 어댑터, 나머지는 SQLAlchemy 하나로 다 커버. `build_explorer(DSN)` 팩토리가 scheme으로 자동 라우팅.
왜
포함
사용성 (이게 목표)
연결이 DSN 한 줄로 끝남:
```bash
LANG2SQL_DB_URL="snowflake://user:pass@account/db?warehouse=wh"
uv sync --extra snowflake # 필요한 드라이버만
```
새 DB 추가 = `pip install <드라이버>` + DSN. 어댑터 코드는 안 건드림.
검증
🤖 Generated with Claude Code