Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use YDB Double for sa Float for compat with 1.4 old dialect #71

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading