Skip to content

Commit

Permalink
order_by() respects use_shortnames
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Sep 24, 2024
1 parent 0c79b7e commit c1dda62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

* **2024.09.24 Current - tSQLike-1.1.5 (candidate)**
* `order_by()` respects `use_shortnames`
* `join_lt()` respects `use_shortnames` for both Tables
* make `_make_shortnames()` method public
* `join()` respects `use_shortnames` for self Table
Expand Down
12 changes: 10 additions & 2 deletions tsqlike/tsqlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,19 +814,27 @@ def select_lt(self, columns='*', where='', comp='==', val='', new_tname='', **kw
comp == 'not in' and _type(r[scol_idx]) not in val])

# -------------------------------------------------------------------------------------------- #
def order_by(self, column='', direction=ORDER_BY_INC, new_tname=''):
def order_by(self, column='', direction=ORDER_BY_INC, new_tname='', **kwargs):

"""
ORDER BY primitive of SQL SELECT
:param column: Order by this column
:param direction: Sort direction ORDER_BY_INC or ORDER_BY_DEC to specify sorting order
:param new_tname: Give a new name for the returned Table
:param **kwargs:
:param use_shortnames if True, Column names in Table header do not contain Table name
:return: A new Table object
"""

header = self.header
if kwargs.get('use_shortnames', self.use_shortnames):
header = self.make_shortnames()


# Extract a column referenced by order_by and sort it
sl = [(self.table[r][self.header.index(column)], r) for r in range(self.rows)]
sl = [(self.table[r][header.index(column)], r) for r in range(self.rows)]
sl.sort()
if direction != ORDER_BY_INC: # Assuming the decreasing order is desired
sl = sl[::-1]
Expand Down

0 comments on commit c1dda62

Please sign in to comment.