Skip to content

✨ Add IntEnum for sqltypes #1337

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
  • Loading branch information
pre-commit-ci[bot] committed Apr 3, 2025
commit acb12ca567db23c7bfab2281bfc013df1f7ac22e
15 changes: 8 additions & 7 deletions sqlmodel/sql/sqltypes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any, cast, Optional, TypeVar
from enum import IntEnum as _IntEnum
from typing import Any, Optional, TypeVar, cast

from sqlalchemy import types
from sqlalchemy.engine.interfaces import Dialect


_TIntEnum = TypeVar('_TIntEnum', bound="_IntEnum")
_TIntEnum = TypeVar("_TIntEnum", bound="_IntEnum")


class AutoString(types.TypeDecorator): # type: ignore
Expand Down Expand Up @@ -56,16 +55,18 @@ def __init__(self, enum_type: _TIntEnum, *args, **kwargs):

self.enum_type = enum_type

def process_result_value(self, value: Optional[int], dialect: Dialect) -> Optional[_TIntEnum]:

def process_result_value(
self, value: Optional[int], dialect: Dialect
) -> Optional[_TIntEnum]:
if value is None:
return None

result = self.enum_type(value)
return result

def process_bind_param(self, value: Optional[_TIntEnum], dialect: Dialect) -> Optional[int]:

def process_bind_param(
self, value: Optional[_TIntEnum], dialect: Dialect
) -> Optional[int]:
if value is None:
return None

Expand Down
Loading