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

Add command to run queries on multiple databases #898

Merged
merged 6 commits into from
Jul 16, 2021

Conversation

shati-patel
Copy link
Contributor

@shati-patel shati-patel commented Jul 2, 2021

Will fix #569.

First pass at adding a new command "CodeQL: Run Query on Multiple Databases", that lets you select multiple databases from a quick pick menu and run a query over all of them. This currently loops over all selected databases and displays results and query history runs for each database separately. If a database is incompatible, we display an error message and skip to the next database.

This might need some design input if we want to do anything fancy with results display 😅

Expand for a (somewhat grainy) demo

multi-db demo

Notes

  • Would this be useful in its current form? (I was mainly experimenting, so suggestions are welcome 🙂)
  • The database quick pick currently lists all databases that are in your Databases UI, including those with the wrong language. I couldn't see an obvious way to filter them...

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • @github/docs-content-codeql has been cc'd in all issues for UI or other user-facing changes made by this pull request. Opened an internal docs issue!

@shati-patel shati-patel changed the title [Don't merge yet] Add command to run queries on multiple databases Add command to run queries on multiple databases Jul 2, 2021
@shati-patel shati-patel marked this pull request as ready for review July 2, 2021 15:44
@shati-patel shati-patel requested a review from a team as a code owner July 2, 2021 15:44
@adityasharad
Copy link
Contributor

This looks very neat, and is a nice compact PR! Just had a quick read, will actually test it out later and then do a proper review.

Copy link
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Tried it out and this was a good experience to use, and the code is nice and clear. Some suggestions on how we can do error handling - ping me if you'd like more detail.

extensions/ql-vscode/src/extension.ts Outdated Show resolved Hide resolved
extensions/ql-vscode/src/extension.ts Outdated Show resolved Hide resolved
commandRunnerWithProgress(
'codeQL.runQueryOnMultipleDatabases',
async (
progress: ProgressCallback,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future note: A cool enhancement might be to have the progress bar reflect how many of the selected databases the query has completed on. Dealing with progress monitors is tricky, so let's think about this later, writing it here just to record the idea.

extensions/ql-vscode/src/extension.ts Show resolved Hide resolved
extensions/ql-vscode/src/extension.ts Outdated Show resolved Hide resolved
if (quickpick !== undefined) {
for (const item of quickpick) {
try {
await compileAndRunQuery(false, uri, progress, token, item.databaseItem);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know the language of the query at this point do we? It would be very cool to automatically filter out databases that are of the wrong language. But no problem if we can't do that yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know the language of the query at this point do we? It would be very cool to automatically filter out databases that are of the wrong language. But no problem if we can't do that yet.

Indeed 😅 I couldn't work out how to extract that language information before displaying the quick pick, so I stuck with this for now!

Copy link
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Add a changelog entry and we're good to go.

): Promise<void> {
if (qs !== undefined) {
const dbItem = await databaseUI.getDatabaseItem(progress, token);
// If no databaseItem is specified, use the database currently selected in the Databases UI
const dbItem = databaseItem || await databaseUI.getDatabaseItem(progress, token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: you could use only one variable throughout:

databaseItem = databaseItem || await databaseUI.getDatabaseItem(progress, token);

and replace dbItem in the two uses below with databaseItem.

Why do this? To avoid accidentally introducing code later that uses databaseItem when we should be using dbItem. (This is a classic mistake I have made often when two variables have similar names but only one variable has the fully initialised value...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed! Thanks for the tip—I can definitely see myself getting confused by variables otherwise 🙃

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.

Add ability to run queries over multiple databases at once
2 participants