sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Document using SQLAlchemy column types; add pydantic.EmailStr support

Open rmasters opened this issue 2 years ago • 10 comments

When I start a new project, I typically start with a User model and always bump into this error:

ValueError: <class 'pydantic.networks.EmailStr'> has no matching SQLAlchemy type

Today I decided to dig into this, and found that EmailStr doesn't subclass str, which explains why it needs a Field(sa_type=String()). I noticed the AutoString types for ipaddress & pathlib, and figured EmailStr might be popular enough to be worth adding (example discussion).

As part of this, in order to test that change I've started documenting how SA column types work in SQLModel. I also noticed the mention about varchar length and documented that too.

Let me know if you'd prefer this as two separate PRs and I can cherry-pick it out - they're only together as I wanted to use the docs-tutorial tests (which are awesome!)


  • [x] Add pydantic.EmailStr support to get_sqlalchemy_type
  • [x] Add documentation for column types, including varchar/text string lengths
  • [ ] ~Finish testing "exotic sqlalchemy type" (geoalchemy2) tests~
    • I originally had some test cases for GIS using geoalchemy2's SQLAlchemy column types. Testing this with sqlite requires libspatialite, which probably needs some CI work/containerization to add this to the environment. I'll revisit this as a separate advanced tutorial in another PR if there's interest.
  • [x] Finish testing ipaddress, pathlib & EmailStr AutoString type alises
  • [ ] Rebase commits to a clean history

rmasters avatar Dec 27 '23 02:12 rmasters

📝 Docs preview for commit 8bd9068b338b16060d2ed5ef623787197fbe8a19 at: https://23112ba0.sqlmodel.pages.dev

github-actions[bot] avatar Dec 27 '23 02:12 github-actions[bot]

📝 Docs preview for commit 0e8c5bcd587ca5f0cf70d7be107f71c8c858bf39 at: https://cb2b259d.sqlmodel.pages.dev

github-actions[bot] avatar Dec 27 '23 13:12 github-actions[bot]

📝 Docs preview for commit 7aead7fc0b802dee0c5e9329c5f8551917857a18 at: https://f76c7357.sqlmodel.pages.dev

github-actions[bot] avatar Dec 27 '23 13:12 github-actions[bot]

📝 Docs preview for commit bae753d33fc1265987691a0202331978b7d5d3e8 at: https://c988b4c3.sqlmodel.pages.dev

github-actions[bot] avatar Dec 31 '23 15:12 github-actions[bot]

📝 Docs preview for commit 8cd7c17b4c8aebff76c1bd5b75bca4707d0d2929 at: https://2b2d516a.sqlmodel.pages.dev

github-actions[bot] avatar Dec 31 '23 15:12 github-actions[bot]

📝 Docs preview for commit 8c45261ee97d5a710506c3592d819a234c867fed at: https://8390b32c.sqlmodel.pages.dev

github-actions[bot] avatar Dec 31 '23 15:12 github-actions[bot]

📝 Docs preview for commit 9a0c172c14da93d884d876653cd886b43048fd4b at: https://fe6eeaf3.sqlmodel.pages.dev

github-actions[bot] avatar Dec 31 '23 16:12 github-actions[bot]

Any update on this MR?

mockingjet avatar Jul 02 '24 06:07 mockingjet