Skip to content

Conversation

@klane
Copy link

@klane klane commented Jun 27, 2022

This PR adds an argument to Field to specify arguments for SQLAlchemy types. It also moves Enum above str when determining the SQLAlchemy type so that classes that extend both Enum and str are identified as Enum. A minimal example for using enums is provided below. It avoids needing to wrap the Enum in a Column and feels more unified with the other column types.

from enum import Enum

from sqlmodel import Field, SQLModel


class MyEnum(str, Enum):
    A = 'A'
    B = 'B'
    C = 'C'


class MyTable(SQLModel, table=True):
    my_enum: MyEnum = Field(sa_type_kwargs={'create_constraint': True})

@tiangolo
Copy link
Member

Thanks! I would rather allow people to pass the full SQLAlchemy type if they want to customize it further. It is now possible with sa_type, in: #505

It will be available in the next version, 0.0.11 🎉

Given that, I'll close this one, but thanks for the effort! ☕

@tiangolo tiangolo closed this Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants