mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-14 20:30:31 +02:00
beaking: Version 1 release
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import enum
|
||||
|
||||
|
||||
# Source: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
||||
class CountryEnum(str, enum.Enum):
|
||||
AF = "Afghanistan"
|
||||
AX = "land Islands"
|
||||
@@ -248,6 +249,7 @@ class CountryEnum(str, enum.Enum):
|
||||
ZW = "Zimbabwe"
|
||||
|
||||
|
||||
# :: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||
class LanguageEnum(str, enum.Enum):
|
||||
AA = "Afar"
|
||||
AB = "Abkhazian"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from .app import * # noqa
|
||||
from .crud import * # noqa
|
||||
from .db import * # noqa
|
||||
from .models import * # noqa
|
||||
from .pagination import * # noqa
|
||||
from .schemas import * # noqa
|
||||
from .testing import * # noqa
|
||||
|
||||
1
creyPY/fastapi/db/__init__.py
Normal file
1
creyPY/fastapi/db/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .session import * # noqa
|
||||
26
creyPY/fastapi/db/session.py
Normal file
26
creyPY/fastapi/db/session.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
from typing import Generator
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
load_dotenv()
|
||||
|
||||
host = os.getenv("POSTGRES_HOST", "localhost")
|
||||
user = os.getenv("POSTGRES_USER", "postgres")
|
||||
password = os.getenv("POSTGRES_PASSWORD", "root")
|
||||
port = os.getenv("POSTGRES_PORT", "5432")
|
||||
name = os.getenv("POSTGRES_DB", "fastapi")
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = f"postgresql+psycopg://{user}:{password}@{host}:{port}/"
|
||||
|
||||
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL + name, pool_pre_ping=True)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
with SessionLocal() as db:
|
||||
yield db
|
||||
Reference in New Issue
Block a user