From 9ed83b89cc9bff856c3b3e7c1f877b242af3f4b3 Mon Sep 17 00:00:00 2001 From: Vladimir Kul'kov Date: Sat, 24 Aug 2024 21:23:57 +1000 Subject: [PATCH] feat: add annotated types to database core --- .../{% if use_sqlalchemy %}core.py{% endif %} | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/project/{{project_name}}/src/{% if use_sqlalchemy %}database{% endif %}/{% if use_sqlalchemy %}core.py{% endif %} b/project/{{project_name}}/src/{% if use_sqlalchemy %}database{% endif %}/{% if use_sqlalchemy %}core.py{% endif %} index 151b14e..d9a9043 100644 --- a/project/{{project_name}}/src/{% if use_sqlalchemy %}database{% endif %}/{% if use_sqlalchemy %}core.py{% endif %} +++ b/project/{{project_name}}/src/{% if use_sqlalchemy %}database{% endif %}/{% if use_sqlalchemy %}core.py{% endif %} @@ -1,8 +1,7 @@ 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, @@ -10,10 +9,11 @@ from sqlalchemy.ext.asyncio import ( ) 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"}, ) @@ -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)] @@ -49,4 +51,5 @@ class Base(DeclarativeBase): str_256: String(256), big_int_pk: BigInteger(), uuid.UUID: types.UUID(), + big_int: BigInteger(), }