initial commit
This commit is contained in:
0
database/__init__.py
Normal file
0
database/__init__.py
Normal file
BIN
database/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
database/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/base.cpython-311.pyc
Normal file
BIN
database/__pycache__/base.cpython-311.pyc
Normal file
Binary file not shown.
18
database/base.py
Normal file
18
database/base.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
|
||||
from settings import PG_LOGIN, PG_PASSWORD, PG_HOST, PG_DATABASE
|
||||
|
||||
DATABASE_URL = f'postgresql+asyncpg://{PG_LOGIN}:{PG_PASSWORD}@{PG_HOST}/{PG_DATABASE}'
|
||||
engine = create_async_engine(DATABASE_URL)
|
||||
session_maker = sessionmaker(engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autocommit=False,
|
||||
autoflush=False)
|
||||
BaseModel = declarative_base()
|
||||
|
||||
|
||||
async def get_session() -> AsyncSession:
|
||||
async with session_maker() as session:
|
||||
yield session
|
||||
1
database/models/__init__.py
Normal file
1
database/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .basic import User
|
||||
BIN
database/models/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
database/models/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
database/models/__pycache__/basic.cpython-311.pyc
Normal file
BIN
database/models/__pycache__/basic.cpython-311.pyc
Normal file
Binary file not shown.
10
database/models/basic.py
Normal file
10
database/models/basic.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
|
||||
from ..base import BaseModel
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
__tablename__ = 'users'
|
||||
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||
login = Column(String, unique=True)
|
||||
password = Column(String, unique=True)
|
||||
Reference in New Issue
Block a user