Skip to content

Commit ac2ad9a

Browse files
committed
Adding erdantic
1 parent cfc7d15 commit ac2ad9a

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

app/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import FastAPI
22
from fastapi.middleware.cors import CORSMiddleware
3+
from fastapi.responses import StreamingResponse
34
import uvicorn
45
from dotenv import load_dotenv
56
import os
@@ -8,6 +9,8 @@
89
from sqlmodel import create_engine, Session, SQLModel, select
910
import strawberry
1011
from strawberry.fastapi import GraphQLRouter
12+
from io import BytesIO
13+
import erdantic as erd
1114
from iris import IrisModel, IrisSQL, load_data, IrisRepository, IrisDocument, IrisDataFrame, IrisQuery, IrisFactory
1215

1316
load_dotenv(osp.join("..", ".env"))
@@ -99,6 +102,16 @@ async def post_sql() -> list[IrisSQL]:
99102
session.refresh(record)
100103
return records
101104

105+
@app.get("/plot")
106+
async def plot_erd():
107+
diagram = erd.create(IrisModel)
108+
buf = BytesIO()
109+
diagram.to_graphviz().draw(
110+
buf, format='jpeg', prog='dot'
111+
)
112+
buf.seek(0)
113+
return StreamingResponse(buf, media_type="image/jpeg")
114+
102115
app.include_router(graphql_app, prefix="/graphql")
103116
app.add_websocket_route("/graphql", graphql_app)
104117

poetry.lock

Lines changed: 79 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pandas = "^2.3.1"
2121
polyfactory = "^2.22.1"
2222
copulas = "^0.12.3"
2323
scikit-learn = "^1.7.1"
24+
erdantic = "^1.1.1"
2425

2526

2627
[build-system]

0 commit comments

Comments
 (0)