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

✨ Add support for passing a custom SQLAlchemy type to Field() with sa_type #505

Merged
merged 13 commits into from
Oct 29, 2023

Conversation

maru0123-2004
Copy link
Contributor

@maru0123-2004 maru0123-2004 commented Nov 23, 2022

Related to #503 .

Notice;
I tested its works only in my case.

@maru0123-2004 maru0123-2004 changed the title Add sa_type to Field to Add sa_type to Field to fix #503 Nov 23, 2022
@github-actions
Copy link

📝 Docs preview for commit 55098b2 at: https://637da5945b0a220ff8ef4e3c--sqlmodel.netlify.app

@github-actions
Copy link

📝 Docs preview for commit c4c58cc at: https://6399e5912bd3820502950046--sqlmodel.netlify.app

@github-actions
Copy link

📝 Docs preview for commit 54d1816 at: https://639cdfbd569504009f94aa64--sqlmodel.netlify.app

@danielkza
Copy link

I just started trying out SQLModel and hit the issue where I can't use a JSON sqlalchemy type, so fixing and merging this PR would be very useufl.

@maru0123-2004
Copy link
Contributor Author

Thank you...!
Is there any error...?

@bkanuka
Copy link

bkanuka commented Feb 19, 2023

FWIW I personally prefer some of the solutions outlined in #503 (adding an override) rather than just adding sa_type. The ideas in #503 have the potential to be more general and helpful in more situations.

@thedamnedrhino
Copy link

thedamnedrhino commented Jun 20, 2023

@danielkza you can do something like this:

from sqlmodel import Column, JSON

class Model(SQLModel):
    # -- adapt field type according to your needs
    subject_sids: dict[str, str] = Field(sa_column=Column(JSON))

@tiangolo tiangolo added the feature New feature or request label Oct 22, 2023
@tiangolo tiangolo changed the title Add sa_type to Field to fix #503 ✨ Add support for passing a custom SQLAlchemy type to Field() with sa_type Oct 29, 2023
@tiangolo
Copy link
Member

Great, thank you @maru0123-2004! 🚀 🍰

This will be available in the next version, 0.0.11 🎉

I will document it (and add tests for it) soon, but later, after migrating to SQLAlchemy 2.0 and Pydantic 2.0. 🤓

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.

5 participants