File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -336,18 +336,33 @@ def offset(self, offset: int = 0):
336336 self ._sql += f" OFFSET { offset } "
337337 return self
338338
339- def order_by (self , field : str = '' , sort : str = 'ASC' ):
340- if field == '' or sort == '' :
341- self .set_error (f"Empty field or sort in { inspect .stack ()[0 ][3 ]} method" )
342- return self
339+ def _prepare_sorting (self , field : str = '' , sort : str = '' ):
340+ if field .find (' ' ) > - 1 :
341+ splitted = field .split (' ' )
342+ field = splitted [0 ]
343+ sort = splitted [1 ]
343344
344- sort = sort .upper ()
345345 field = field .replace ('.' , '`.`' )
346346
347+ if sort == '' :
348+ sort = 'ASC'
349+ else :
350+ sort = sort .upper ()
351+
352+ return field , sort
353+
354+ def order_by (self , field : str = '' , sort : str = '' ):
355+ if field == '' :
356+ self .set_error (f"Empty field in { inspect .stack ()[0 ][3 ]} method" )
357+ return self
358+
359+ field , sort = self ._prepare_sorting (field , sort )
360+
347361 if sort in self ._SORT_TYPES :
348362 self ._sql += f" ORDER BY `{ field } ` { sort } "
349363 else :
350364 self ._sql += f" ORDER BY `{ field } `"
365+
351366 return self
352367
353368 def group_by (self , field : str = '' ):
You can’t perform that action at this time.
0 commit comments