-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to sqlalchemy select API and FastAPI SessionDep
- Loading branch information
1 parent
358aa8f
commit 3c1618e
Showing
6 changed files
with
38 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import Depends | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlalchemy.orm import Session | ||
|
||
|
||
# pass empty connection string to use PG* environment variables (see https://www.postgresql.org/docs/current/libpq-envars.html) | ||
engine = create_engine("postgresql+psycopg2://", future=True, pool_pre_ping=True) | ||
|
||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
def get_session(): | ||
with Session(engine) as session: | ||
yield session | ||
|
||
|
||
SessionDep = Annotated[Session, Depends(get_session)] | ||
|
||
Base = declarative_base() |