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

[sqlite ] exec-sql command create sheets with unique or helpful names. #2136

Open
5 tasks
frosencrantz opened this issue Nov 25, 2023 · 5 comments
Open
5 tasks
Labels

Comments

@frosencrantz
Copy link
Contributor

@saulpw added this wonderful exec-sql command in response to #1719

The wishlist item is to make that command more useful.

  • The command always creates sheets with the same name query. Add a way to automatically create unique names for the sheets like make the name based on the query, or simply add a unique count suffix to the sheet name query1, query2, etc.
    • Add an input field for specifying the sheet name
  • Make it easy to see the query associated with the sheet. I can not see this in the SheetsSheet. There is likely a way to do it, but I do not know.
  • Make it easy to make an edit to the query used and create a new sheet
  • Add column types
@midichef
Copy link
Contributor

midichef commented Dec 27, 2023

add a unique count suffix to the sheet name query1, query2, etc.

This works, in .visidatarc making names like 'query_01', 'query_02' etc for easier sortability:

@SqliteSheet.api
def rawSql(self, q:str) -> 'SqliteSheet':
    if not hasattr(self, 'query_ctr'):
        self.query_ctr = 0
    self.query_ctr += 1
    return SqliteSheet(f'query_{self.query_ctr:>02}', source=self.source, query=q)

see the query associated with the sheet. I can not see this in the SheetsSheet. There is likely a way to do it, but I do not know.

To see the query on SheetsSheet, = and then row.query

@frosencrantz
Copy link
Contributor Author

Thanks, @midichef! Those are both useful tips.

I think vd should handle generating the unique names for the query sheets. But if it doesn't this works.

@dufferzafar
Copy link
Contributor

@frosencrantz I was taking a look at the implementation of this to figure out if I can find an easy way to display the SQL query, because being able to view/edit/retrigger the query definitely sounds useful.

I thought perhaps I could reuse the source column in the SheetsSheet for this purpose and show the query there, which you could perhaps copy/paste in exec-sql command again?

But I couldn't get the sources bit to work, it seems source requires a Sheet .

@midichef
Copy link
Contributor

midichef commented Feb 12, 2024

@frosencrantz @dufferzafar
Try this in your .visidatarc, it should add a query column to SheetsSheet, you can edit it with edit-cell and it will reload after each edit:

SheetsSheet.columns.append(
    Column('query',
        getter=lambda c,r: getattr(r, 'query') if isinstance(r, SqliteSheet) else None,
        setter=lambda c,r,v: (setattr(r, 'query', v), r.reload()) if isinstance(r, SqliteSheet) else None
    )
)

You could change the order of the columns by changing .append( to .insert(1, to make it faster to get to the query. And you can customize the width by changing Column('query', to Column('query', width=80,

@frosencrantz
Copy link
Contributor Author

Thank you @midichef! I just tried this and it works great.

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

No branches or pull requests

3 participants