|
1 | 1 | # ducktools.env |
2 | 2 | # MIT License |
3 | | -# |
| 3 | +# |
4 | 4 | # Copyright (c) 2024 David C Ellis |
5 | | -# |
| 5 | +# |
6 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 | # of this software and associated documentation files (the "Software"), to deal |
8 | 8 | # in the Software without restriction, including without limitation the rights |
9 | 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | 10 | # copies of the Software, and to permit persons to whom the Software is |
11 | 11 | # furnished to do so, subject to the following conditions: |
12 | | -# |
| 12 | +# |
13 | 13 | # The above copyright notice and this permission notice shall be included in all |
14 | 14 | # copies or substantial portions of the Software. |
15 | | -# |
| 15 | +# |
16 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
@@ -106,8 +106,14 @@ def validate_field(self): |
106 | 106 | raise AttributeError("Primary key fields are already unique") |
107 | 107 |
|
108 | 108 |
|
109 | | -def get_sql_fields(cls: "SQLMeta") -> dict[str, SQLAttribute]: |
110 | | - return get_attributes(cls) # noqa |
| 109 | +def get_sql_fields(cls: "SQLMeta", local=False) -> dict[str, SQLAttribute]: |
| 110 | + attribs = get_attributes(cls, local=local) |
| 111 | + parents = SQLAttribute.__mro__[1:-1] # remove object and self |
| 112 | + attributes = { |
| 113 | + k: SQLAttribute.from_field(v) if type(v) in parents else v |
| 114 | + for k, v in attribs.items() |
| 115 | + } |
| 116 | + return attributes |
111 | 117 |
|
112 | 118 |
|
113 | 119 | unified_gatherer = make_unified_gatherer(SQLAttribute) |
@@ -154,7 +160,14 @@ def __init_subclass__( |
154 | 160 | **kwargs, |
155 | 161 | ): |
156 | 162 | slots = "__slots__" in cls.__dict__ |
157 | | - builder(cls, gatherer=gatherer, methods=methods, flags={"slotted": slots, "kw_only": True}) |
| 163 | + |
| 164 | + builder( |
| 165 | + cls, |
| 166 | + gatherer=gatherer, |
| 167 | + methods=methods, |
| 168 | + flags={"slotted": slots, "kw_only": True}, |
| 169 | + field_getter=get_sql_fields, |
| 170 | + ) |
158 | 171 |
|
159 | 172 | fields = get_sql_fields(cls) |
160 | 173 | valid_fields = {} |
|
0 commit comments