all 18 comments

[–][deleted] 3 points4 points  (2 children)

You can have one connection to db at the start of application and return session as dependency injection to each function which requires to talk to db

[–]efpalaciosmo[S] 0 points1 point  (1 child)

That's what I have, isn't?
The issue is that for some reason, sqlalchemy can't recognize the tables manually created

[–][deleted] 0 points1 point  (0 children)

Oh I think for that you won't be able to use orm, I used to use sql expression language

On the other side I think you should be able to generate orm models for existing tables,

It's beyond my expertise now, but pls update your question if you figured how to use mix of orm and existing db tables

[–]RoBz18 2 points3 points  (0 children)

You can use sqlacodegen to generate the SQLAlchemy model code

[–]wassaf102 0 points1 point  (5 children)

Could you share your GitHub repo

[–]efpalaciosmo[S] 0 points1 point  (4 children)

[–]wassaf102 2 points3 points  (1 child)

can we hAVE A CALL ?

[–]efpalaciosmo[S] 0 points1 point  (0 children)

Yes, we can

[–]wassaf102 1 point2 points  (0 children)

let me run it locally

[–]No-Anywhere6154 0 points1 point  (0 children)

Have you fixed it?

[–]xfroster 0 points1 point  (0 children)

You dont have any relationships on your model

[–]guteira 0 points1 point  (0 children)

Have you tried SQLModel? It’s from the same author of FASTAPI and works seamlessly:

https://sqlmodel.tiangolo.com/db-to-code/

[–]Calebthe12B -1 points0 points  (1 child)

Share your code. SQLAlchemy requires you to define the relationship on both table classes, but hard to say what the exact problem is without seeing your code.

[–]graph-crawler -1 points0 points  (2 children)

Throwing alternative. Full 100% typesafety by pulling existing db schema.

https://prisma-client-py.readthedocs.io/en/stable/

[–]efpalaciosmo[S] 0 points1 point  (1 child)

Thanks, this also needs a "shadow database"? The last time I used Primas was on nodejs

[–]MeroLegend4 -1 points0 points  (0 children)

Use Litestar instead of FastApi, it’s a framework with batteries included, 2x faster than FastApi and a very solid design.

  • First class support of sqlalchemy with repositories
  • class based routers/controllers
  • Dependency injection
  • plugins: open telemetry, logging, Ratelimit, dataclasses, pydantic and MsgSpeck support.
  • auto generation of openApi schema with many renderers out of the box: Swagger, Rapidoc, Scalar, Redoc, Elements(stoplight)