Skip to content

Commit

Permalink
feat: add annotated types to database core
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Kul'kov committed Aug 24, 2024
1 parent 5b1bcee commit 9ed83b8
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import uuid
from typing import Annotated

from config import get_db_settings
from sqlalchemy import BigInteger, Boolean, Integer, String, types
from sqlalchemy import BigInteger, Boolean, String, types
from sqlalchemy.ext.asyncio import (
AsyncSession,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy.orm import DeclarativeBase, mapped_column

from config import get_db_settings

db_settings = get_db_settings()
engine = create_async_engine(
db_settings.DSN.unicode_string(),
future=True,
echo=False,
execution_options={"isolation_level": "AUTOCOMMIT"},
)
Expand All @@ -30,16 +30,18 @@ str_256_unique_not_null = Annotated[
str, mapped_column(String(256), nullable=False, unique=True)
]
str_256_nullable = Annotated[str, mapped_column(String(256), nullable=True)]
str_256_nullable_uniq = Annotated[
str, mapped_column(String(256), nullable=True, unique=True)
]
str_256 = Annotated[str, String(256)]
guid_pk = Annotated[
uuid.UUID, mapped_column(primary_key=True, default=uuid.uuid4)
]
int_pk = Annotated[int, mapped_column(primary_key=True)]
big_int_pk = Annotated[
int, mapped_column(BigInteger, nullable=False, primary_key=True)
]
int_pk = Annotated[
int, mapped_column(Integer, nullable=False, primary_key=True)
]
big_int = Annotated[int, mapped_column(BigInteger, nullable=False, primary_key=True)]
bool_default_false = Annotated[bool, mapped_column(Boolean, default=False)]


Expand All @@ -49,4 +51,5 @@ class Base(DeclarativeBase):
str_256: String(256),
big_int_pk: BigInteger(),
uuid.UUID: types.UUID(),
big_int: BigInteger(),
}

0 comments on commit 9ed83b8

Please sign in to comment.