Skip to content

Commit 2eacadb

Browse files
authored
Merge pull request #71 from ydb-platform/float_double_sa_14
Use YDB Double for sa Float for compat with 1.4 old dialect
2 parents 9e6d8cf + 022e525 commit 2eacadb

File tree

1 file changed

+21
-1
lines changed
  • ydb_sqlalchemy/sqlalchemy/compiler

1 file changed

+21
-1
lines changed

ydb_sqlalchemy/sqlalchemy/compiler/sa14.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from typing import Union
2+
import sqlalchemy as sa
3+
import ydb
4+
15
from .base import (
26
BaseYqlCompiler,
37
BaseYqlDDLCompiler,
@@ -7,7 +11,23 @@
711

812

913
class YqlTypeCompiler(BaseYqlTypeCompiler):
10-
...
14+
# We use YDB Double for sa.Float for compatibility with old dialect version
15+
def visit_FLOAT(self, type_: sa.FLOAT, **kw):
16+
return "DOUBLE"
17+
18+
def get_ydb_type(
19+
self, type_: sa.types.TypeEngine, is_optional: bool
20+
) -> Union[ydb.PrimitiveType, ydb.AbstractTypeBuilder]:
21+
if isinstance(type_, sa.TypeDecorator):
22+
type_ = type_.impl
23+
24+
if isinstance(type_, sa.Float):
25+
ydb_type = ydb.PrimitiveType.Double
26+
if is_optional:
27+
return ydb.OptionalType(ydb_type)
28+
return ydb_type
29+
30+
return super().get_ydb_type(type_, is_optional)
1131

1232

1333
class YqlIdentifierPreparer(BaseYqlIdentifierPreparer):

0 commit comments

Comments
 (0)