FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add option to pass kwargs to SQLAlchemy types by klane · Pull Request #366 · fastapi/sqlmodel · GitHub

Repository navigation

Add option to pass kwargs to SQLAlchemy types - #366

Closed
klane wants to merge 1 commit into
fastapi:mainfrom
klane:sa-type-args
Closed

klane wants to merge 1 commit into
fastapi:mainfrom
klane:sa-type-args

Conversation

klane commented Jun 27, 2022

Copy link
Copy Markdown

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})

Copy link
Copy Markdown
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 closed this Oct 29, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL