forked from retoor/devplacepy
feat: add admin/internal database API with CRUD, read-only query, and natural-language SQL endpoints
Add a new `/dbapi` router package providing a generic database API over `dataset`, restricted to admin sessions, admin API keys, and the internal gateway key. Includes: - `tables.py`: list all tables and inspect table schemas - `crud.py`: full CRUD operations (GET, POST, PATCH, DELETE) with soft-delete awareness, born-live inserts, `?include_deleted`, `.../restore`, and `?hard=true` purge - `query.py`: validated read-only SELECT execution via sqlglot parsing, classification, and EXPLAIN dry-run; async query jobs with WebSocket streaming via `DbApiJobService` - `nl.py`: natural-language-to-SQL conversion using the platform AI gateway with re-prompting until validation passes Also register `DbApiJobService` and `PubSubService` in the service manager, add `DBAPI_DIR` to config data paths, and force cleartext `http://` connections to HTTP/1.1 in `curl_transport` to fix large request failures against uvicorn's HTTP/1.1-only internal gateway.
This commit is contained in:
@@ -45,6 +45,12 @@ HTTP_VERSION_LABELS: dict[int, bytes] = {
|
||||
}
|
||||
|
||||
|
||||
def http_version_for(url: httpx.URL):
|
||||
if url.scheme == "http":
|
||||
return CurlHttpVersion.V1_1
|
||||
return None
|
||||
|
||||
|
||||
def resolve_timeout(request: httpx.Request) -> float:
|
||||
extension = request.extensions.get("timeout") or {}
|
||||
for key in ("read", "connect", "pool"):
|
||||
@@ -79,6 +85,10 @@ class CurlTransport(httpx.AsyncBaseTransport):
|
||||
if key.lower() not in STRIP_REQUEST_HEADERS
|
||||
}
|
||||
body = await request.aread()
|
||||
extra = {}
|
||||
version = http_version_for(request.url)
|
||||
if version is not None:
|
||||
extra["http_version"] = version
|
||||
try:
|
||||
response = await self._session.request(
|
||||
request.method,
|
||||
@@ -90,6 +100,7 @@ class CurlTransport(httpx.AsyncBaseTransport):
|
||||
stream=True,
|
||||
allow_redirects=False,
|
||||
timeout=resolve_timeout(request),
|
||||
**extra,
|
||||
)
|
||||
except Timeout as exc:
|
||||
raise httpx.ConnectTimeout(str(exc), request=request) from exc
|
||||
|
||||
Reference in New Issue
Block a user