sqlalchemy-studio 0.1.5__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlalchemy-studio
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: FastAPI studio for inspecting SQLAlchemy databases
5
5
  Author-email: Xursand Qarlibayev <coderxuz2009@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sqlalchemy-studio"
7
- version = "0.1.5"
7
+ version = "0.1.6"
8
8
  description = "FastAPI studio for inspecting SQLAlchemy databases"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -1,10 +1,12 @@
1
1
  from sqlalchemy import and_, create_engine, func, inspect, Engine, or_, select, Table
2
2
  from sqlalchemy.engine.interfaces import ReflectedColumn
3
3
  from sqlalchemy.orm import DeclarativeBase
4
- from fastapi import FastAPI, HTTPException, status
4
+ from fastapi import FastAPI, HTTPException, status, Request
5
5
  from fastapi.middleware.cors import CORSMiddleware
6
6
  from fastapi.staticfiles import StaticFiles
7
7
  from importlib.resources import files
8
+ from fastapi.responses import FileResponse
9
+ from starlette.exceptions import HTTPException as StarletteHTTPException
8
10
  import uvicorn
9
11
 
10
12
 
@@ -78,6 +80,21 @@ class Studio:
78
80
  StaticFiles(directory=str(static_dir), html=True),
79
81
  name="static",
80
82
  )
83
+ # SPA fallback: return index.html for any non-API path so client-side
84
+ # routing (e.g. /tables/users) works. Keep API routes handled above.
85
+ index_file = static_dir.joinpath("index.html")
86
+ if index_file.exists():
87
+
88
+ async def spa_404_handler(
89
+ request: Request, exc: StarletteHTTPException
90
+ ):
91
+ if exc.status_code == 404 and not request.url.path.startswith(
92
+ "/api"
93
+ ):
94
+ return FileResponse(str(index_file))
95
+ raise exc
96
+
97
+ self.app.add_exception_handler(StarletteHTTPException, spa_404_handler)
81
98
 
82
99
  def run(self, port: int = 8000):
83
100
  print("-" * 50)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlalchemy-studio
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: FastAPI studio for inspecting SQLAlchemy databases
5
5
  Author-email: Xursand Qarlibayev <coderxuz2009@gmail.com>
6
6
  License: MIT