diff --git a/ydb_sqlalchemy/sqlalchemy/compiler/sa14.py b/ydb_sqlalchemy/sqlalchemy/compiler/sa14.py index dbe931a..598fc29 100644 --- a/ydb_sqlalchemy/sqlalchemy/compiler/sa14.py +++ b/ydb_sqlalchemy/sqlalchemy/compiler/sa14.py @@ -1,3 +1,7 @@ +from typing import Union +import sqlalchemy as sa +import ydb + from .base import ( BaseYqlCompiler, BaseYqlDDLCompiler, @@ -7,7 +11,23 @@ class YqlTypeCompiler(BaseYqlTypeCompiler): - ... + # We use YDB Double for sa.Float for compatibility with old dialect version + def visit_FLOAT(self, type_: sa.FLOAT, **kw): + return "DOUBLE" + + def get_ydb_type( + self, type_: sa.types.TypeEngine, is_optional: bool + ) -> Union[ydb.PrimitiveType, ydb.AbstractTypeBuilder]: + if isinstance(type_, sa.TypeDecorator): + type_ = type_.impl + + if isinstance(type_, sa.Float): + ydb_type = ydb.PrimitiveType.Double + if is_optional: + return ydb.OptionalType(ydb_type) + return ydb_type + + return super().get_ydb_type(type_, is_optional) class YqlIdentifierPreparer(BaseYqlIdentifierPreparer):