-
-
Notifications
You must be signed in to change notification settings - Fork 821
Expand file tree
/
Copy pathsqltypes.py
More file actions
16 lines (12 loc) · 558 Bytes
/
sqltypes.py
File metadata and controls
16 lines (12 loc) · 558 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from typing import Any, cast
from sqlalchemy import types
from sqlalchemy.engine.interfaces import Dialect
class AutoString(types.TypeDecorator): # type: ignore
impl = types.String
cache_ok = True
mysql_default_length = 255
def load_dialect_impl(self, dialect: Dialect) -> "types.TypeEngine[Any]":
impl = cast(types.String, self.impl)
if impl.length is None and dialect.name == "mysql":
return dialect.type_descriptor(types.String(self.mysql_default_length))
return super().load_dialect_impl(dialect)