@@ -42,7 +42,7 @@ def __init__(
42
42
update_route : Union [bool , DEPENDENCIES ] = True ,
43
43
delete_one_route : Union [bool , DEPENDENCIES ] = True ,
44
44
delete_all_route : Union [bool , DEPENDENCIES ] = True ,
45
- ** kwargs : Any
45
+ ** kwargs : Any ,
46
46
) -> None :
47
47
assert (
48
48
sqlalchemy_installed
@@ -66,7 +66,7 @@ def __init__(
66
66
update_route = update_route ,
67
67
delete_one_route = delete_one_route ,
68
68
delete_all_route = delete_all_route ,
69
- ** kwargs
69
+ ** kwargs ,
70
70
)
71
71
72
72
def _get_all (self , * args : Any , ** kwargs : Any ) -> CALLABLE_LIST :
@@ -100,7 +100,6 @@ def route(
100
100
101
101
return route
102
102
103
-
104
103
def _get_orm_object (self , db : Session , orm_model : Model , model : Model ) -> Any :
105
104
query = db .query (orm_model )
106
105
filter_items = 0
@@ -110,10 +109,9 @@ def _get_orm_object(self, db: Session, orm_model: Model, model: Model) -> Any:
110
109
query = query .filter (column (key ) == val )
111
110
if filter_items == 0 :
112
111
raise Exception ("No attributes for filter found" )
113
- return query .one ()
114
-
112
+ return query .one ()
115
113
116
- def _get_orm_object_or_value (self , db : Session , val : Any ) -> Any :
114
+ def _get_orm_object_or_value (self , db : Session , val : Any ) -> Any :
117
115
"""Return an inflated database object or a plain value.
118
116
119
117
If a `val` is a SqlModel type and has defined a Meta.orm model
@@ -133,16 +131,14 @@ def _get_orm_object_or_value(self, db: Session, val: Any) -> Any:
133
131
return self ._get_orm_object (db , orm_model , val )
134
132
return val
135
133
136
-
137
134
def _create (self , * args : Any , ** kwargs : Any ) -> CALLABLE :
138
-
139
135
def route (
140
136
model : self .create_schema , # type: ignore
141
137
db : Session = Depends (self .db_func ),
142
138
) -> Model :
143
139
try :
144
140
db_model : Model = self .db_model ()
145
-
141
+
146
142
for key , val in model :
147
143
if val :
148
144
setattr (db_model , key , self ._get_orm_object_or_value (db , val ))
@@ -169,7 +165,9 @@ def route(
169
165
for key , val in model :
170
166
if key != self ._pk :
171
167
if hasattr (db_model , key ):
172
- setattr (db_model , key , self ._get_orm_object_or_value (db , val ))
168
+ setattr (
169
+ db_model , key , self ._get_orm_object_or_value (db , val )
170
+ )
173
171
174
172
db .commit ()
175
173
db .refresh (db_model )
0 commit comments