Skip to content

Commit

Permalink
Merge pull request #71 from ydb-platform/float_double_sa_14
Browse files Browse the repository at this point in the history
Use YDB Double for sa Float for compat with 1.4 old dialect
  • Loading branch information
vgvoleg authored Jan 13, 2025
2 parents 9e6d8cf + 022e525 commit 2eacadb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ydb_sqlalchemy/sqlalchemy/compiler/sa14.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import Union
import sqlalchemy as sa
import ydb

from .base import (
BaseYqlCompiler,
BaseYqlDDLCompiler,
Expand All @@ -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):
Expand Down

0 comments on commit 2eacadb

Please sign in to comment.