1
1
import ipaddress
2
+ from sqlalchemy .sql .type_api import TypeEngine
2
3
import uuid
3
4
import weakref
4
5
from datetime import date , datetime , time , timedelta
@@ -72,6 +73,7 @@ def __init__(self, default: Any = Undefined, **kwargs: Any) -> None:
72
73
foreign_key = kwargs .pop ("foreign_key" , Undefined )
73
74
index = kwargs .pop ("index" , Undefined )
74
75
sa_column = kwargs .pop ("sa_column" , Undefined )
76
+ sa_column_type = kwargs .pop ("sa_column_type" , Undefined )
75
77
sa_column_args = kwargs .pop ("sa_column_args" , Undefined )
76
78
sa_column_kwargs = kwargs .pop ("sa_column_kwargs" , Undefined )
77
79
if sa_column is not Undefined :
@@ -91,6 +93,7 @@ def __init__(self, default: Any = Undefined, **kwargs: Any) -> None:
91
93
self .foreign_key = foreign_key
92
94
self .index = index
93
95
self .sa_column = sa_column
96
+ self .sa_column_type = sa_column_type
94
97
self .sa_column_args = sa_column_args
95
98
self .sa_column_kwargs = sa_column_kwargs
96
99
@@ -153,6 +156,7 @@ def Field(
153
156
nullable : Union [bool , UndefinedType ] = Undefined ,
154
157
index : Union [bool , UndefinedType ] = Undefined ,
155
158
sa_column : Union [Column , UndefinedType ] = Undefined ,
159
+ sa_column_type : Union [TypeEngine , UndefinedType ] = Undefined ,
156
160
sa_column_args : Union [Sequence [Any ], UndefinedType ] = Undefined ,
157
161
sa_column_kwargs : Union [Mapping [str , Any ], UndefinedType ] = Undefined ,
158
162
schema_extra : Optional [Dict [str , Any ]] = None ,
@@ -183,6 +187,7 @@ def Field(
183
187
nullable = nullable ,
184
188
index = index ,
185
189
sa_column = sa_column ,
190
+ sa_column_type = sa_column_type ,
186
191
sa_column_args = sa_column_args ,
187
192
sa_column_kwargs = sa_column_kwargs ,
188
193
** current_schema_extra ,
@@ -412,7 +417,11 @@ def get_column_from_field(field: ModelField) -> Column:
412
417
sa_column = getattr (field .field_info , "sa_column" , Undefined )
413
418
if isinstance (sa_column , Column ):
414
419
return sa_column
415
- sa_type = get_sqlachemy_type (field )
420
+ sa_column_type = getattr (field .field_info , "sa_column_type" , Undefined )
421
+ if sa_column_type is not Undefined :
422
+ sa_type = sa_column_type
423
+ else :
424
+ sa_type = get_sqlachemy_type (field )
416
425
primary_key = getattr (field .field_info , "primary_key" , False )
417
426
nullable = not field .required
418
427
index = getattr (field .field_info , "index" , Undefined )
0 commit comments