Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
.env
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# environment variables
.env
27 changes: 14 additions & 13 deletions db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

from dotenv import load_dotenv
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool

load_dotenv(".env")


def get_postgres_uri():
DB_HOST = os.getenv('POSTGRES_DB_HOST')
DB_NAME = os.getenv('POSTGRES_DB_NAME')
DB_USER = os.getenv('POSTGRES_DB_USER')
DB_PASS = os.getenv('POSTGRES_DB_PASS')
DB_HOST = os.getenv("POSTGRES_DB_HOST")
DB_NAME = os.getenv("POSTGRES_DB_NAME")
DB_USER = os.getenv("POSTGRES_DB_USER")
DB_PASS = os.getenv("POSTGRES_DB_PASS")

return f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}/{DB_NAME}"

return f'postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}/{DB_NAME}'


class PostgresORM:

def __init__(self):
DATABASE_URL = get_postgres_uri()
DATABASE_URL = get_postgres_uri()
# Initialize Async SQLAlchemy
engine = create_async_engine(DATABASE_URL, echo=False,poolclass=NullPool)
async_session = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession)
engine = create_async_engine(DATABASE_URL, echo=False, poolclass=NullPool)
async_session = sessionmaker(
autocommit=False, autoflush=False, bind=engine, class_=AsyncSession
)
self.session = async_session

def get_instance():
return PostgresORM()
return PostgresORM()
Binary file removed db/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed db/__pycache__/models.cpython-310.pyc
Binary file not shown.
Loading