Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reversing the order of displayed results #18

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tyler-ham
Copy link

Example Use Case:

I wanted to display a query showing the 100 most recent commands, but displayed in ascending chronological order. If I configured the ORDER BY clause of the SQL to sort in chronological order, the --limit 100 parameter would give me the oldest 100 commands, not the most recent. Alternatively, if I configured the ORDER BY clause to sort in reverse chronological order, the --limit 100 parameter would correctly give me the most recent 100 commands. However, they would be displayed in reverse chronological order, with the most recent commands scrolling off the screen.

Proposed Solution in this PR:

The proposed solution in this pull request is to add a --reverse flag to ash_query and ash_query.py to control the order in which the query results are displayed.

This way, for my example use case above, I could configure the ORDER BY clause to sort in reverse chronological order, let the --limit be applied to return the most recent set of commands, and then let the --reverse flag apply to display them in ascending chronological order.

Example:

queries: (queries commands in reverse chronological order)

MYHISTORY: {
  description: "List all commands in history."
  sql: {
    select
      c.session_id,
      datetime(c.start_time, 'unixepoch', 'localtime') as 'when',
      c.command
    from
      commands as c
    order by
      c.start_time DESC
    ;
  }
}

Query:

ash_query -q MYHISTORY --limit 3

Results (reverse chronological order):

session_id    when                   command
13448         2020-12-20 13:13:54    echo "test 123"
13448         2020-12-19 13:03:27    cat hello-world.txt
13448         2020-12-18 13:03:17    ls -la

Query with reverse:

ash_query -q MYHISTORY --limit 3 --reverse

Results with reverse (ascendig chronological order):

session_id    when                   command
13448         2020-12-18 13:03:17    ls -la
13448         2020-12-19 13:03:27    cat hello-world.txt
13448         2020-12-20 13:13:54    echo "test 123"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant