fastapi / sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.
https://sqlmodel.tiangolo.com/
MIT License
14.43k stars 658 forks source link

Specifying SQL Server column data type, similar to dtype in pd.to_sql() #319

Open HansOlavMyklebust opened 2 years ago

HansOlavMyklebust commented 2 years ago

First Check

Commit to Help

Example Code

from typing import Optional

from sqlmodel import Field, SQLModel
from sqlalchemy.typing import NVARCHAR

class Hero(SQLModel, table=True):
    id: str = Field(default=None, primary_key=True, dtype=NVARCHAR(32))
    name: str
    secret_name: str
    age: Optional[int] = None

Description

Create a SQLModel that contains a mapping between python type (e.g str) and SQL Server column type (e.g NVARCHAR(32)). This is possible to do when using pandas to_sql() by specifying the dtype-argument.

Operating System

Linux, Windows

Operating System Details

No response

SQLModel Version

0.0.6

Python Version

Python 3.9.7

Additional Context

No response

JacobHayes commented 5 months ago

I think this is supported now with sa_type.