sql-athame 0.4.0a7__tar.gz → 0.4.0a8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/PKG-INFO +1 -1
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/pyproject.toml +1 -1
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/dataclasses.py +34 -25
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/LICENSE +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/README.md +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/__init__.py +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/base.py +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/escape.py +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/py.typed +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/sqlalchemy.py +0 -0
- {sql_athame-0.4.0a7 → sql_athame-0.4.0a8}/sql_athame/types.py +0 -0
@@ -10,6 +10,7 @@ from typing import (
|
|
10
10
|
Optional,
|
11
11
|
TypeVar,
|
12
12
|
Union,
|
13
|
+
get_args,
|
13
14
|
get_origin,
|
14
15
|
get_type_hints,
|
15
16
|
)
|
@@ -84,6 +85,22 @@ class ConcreteColumnInfo:
|
|
84
85
|
return " ".join(parts)
|
85
86
|
|
86
87
|
|
88
|
+
NULLABLE_TYPES = (type(None), Any, object)
|
89
|
+
|
90
|
+
|
91
|
+
def split_nullable(typ: type) -> tuple[bool, type]:
|
92
|
+
nullable = typ in NULLABLE_TYPES
|
93
|
+
if get_origin(typ) is Union:
|
94
|
+
args = []
|
95
|
+
for arg in get_args(typ):
|
96
|
+
if arg in NULLABLE_TYPES:
|
97
|
+
nullable = True
|
98
|
+
else:
|
99
|
+
args.append(arg)
|
100
|
+
return nullable, Union[tuple(args)] # type: ignore
|
101
|
+
return nullable, typ
|
102
|
+
|
103
|
+
|
87
104
|
sql_create_type_map = {
|
88
105
|
"BIGSERIAL": "BIGINT",
|
89
106
|
"SERIAL": "INTEGER",
|
@@ -91,23 +108,15 @@ sql_create_type_map = {
|
|
91
108
|
}
|
92
109
|
|
93
110
|
|
94
|
-
sql_type_map: dict[Any,
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
bool: ("BOOLEAN", False),
|
104
|
-
bytes: ("BYTEA", False),
|
105
|
-
datetime.date: ("DATE", False),
|
106
|
-
datetime.datetime: ("TIMESTAMP", False),
|
107
|
-
float: ("DOUBLE PRECISION", False),
|
108
|
-
int: ("INTEGER", False),
|
109
|
-
str: ("TEXT", False),
|
110
|
-
uuid.UUID: ("UUID", False),
|
111
|
+
sql_type_map: dict[Any, str] = {
|
112
|
+
bool: "BOOLEAN",
|
113
|
+
bytes: "BYTEA",
|
114
|
+
datetime.date: "DATE",
|
115
|
+
datetime.datetime: "TIMESTAMP",
|
116
|
+
float: "DOUBLE PRECISION",
|
117
|
+
int: "INTEGER",
|
118
|
+
str: "TEXT",
|
119
|
+
uuid.UUID: "UUID",
|
111
120
|
}
|
112
121
|
|
113
122
|
|
@@ -171,16 +180,16 @@ class ModelBase:
|
|
171
180
|
def column_info_for_field(cls, field: Field) -> ConcreteColumnInfo:
|
172
181
|
type_info = cls.type_hints()[field.name]
|
173
182
|
base_type = type_info
|
183
|
+
metadata = []
|
174
184
|
if get_origin(type_info) is Annotated:
|
175
|
-
base_type = type_info
|
176
|
-
|
185
|
+
base_type, *metadata = get_args(type_info)
|
186
|
+
nullable, base_type = split_nullable(base_type)
|
187
|
+
info = [ColumnInfo(nullable=nullable)]
|
177
188
|
if base_type in sql_type_map:
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
if isinstance(md, ColumnInfo):
|
183
|
-
info.append(md)
|
189
|
+
info.append(ColumnInfo(type=sql_type_map[base_type]))
|
190
|
+
for md in metadata:
|
191
|
+
if isinstance(md, ColumnInfo):
|
192
|
+
info.append(md)
|
184
193
|
return ConcreteColumnInfo.from_column_info(field.name, *info)
|
185
194
|
|
186
195
|
@classmethod
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|