File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,15 +109,34 @@ async def add(cls,
109109 session : AsyncSession ,
110110 ** values ,
111111 ) -> BaseModel :
112- async with session .begin ():
113- instance = cls .model (** values )
114- session .add (instance = instance )
115- try :
116- await session .commit ()
117- except SQLAlchemyError as ex :
118- await session .rollback ()
119- raise ex
120- return instance
112+ instance = cls .model (** values )
113+ session .add (instance = instance )
114+ try :
115+ await session .commit ()
116+ except SQLAlchemyError as ex :
117+ await session .rollback ()
118+ raise ex
119+ return instance
120+
121+ @classmethod
122+ async def update (cls ,
123+ session : AsyncSession ,
124+ instance : BaseModel ,
125+ ** values ,
126+ ) -> BaseModel :
127+ [setattr (instance , name , value )
128+ for name , value
129+ in values .items ()]
130+ await session .commit ()
131+ return instance
132+
133+ @classmethod
134+ async def delete (cls ,
135+ session : AsyncSession ,
136+ instance : BaseModel ,
137+ ) -> None :
138+ await session .delete (instance )
139+ await session .commit ()
121140
122141
123142def struct_options_statment (model : BaseModel ,
You can’t perform that action at this time.
0 commit comments