Visitar URL original
Add export parameters to ResultTabs and QueryTab components by Stelinkaa · Pull Request #1427 · dbgate/dbgate · GitHub
Skip to content

Add export parameters to ResultTabs and QueryTab components - #1427

Draft
Stelinkaa wants to merge 3 commits into
masterfrom
feature/query-export-limit
Draft

Stelinkaa wants to merge 3 commits into
masterfrom
feature/query-export-limit

Conversation

@Stelinkaa

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR threads “export context” (connection/database/executed SQL) from QueryTab → ResultTabs → JslDataGrid so that exporting a limited query result can re-run the original query for export (instead of exporting only the limited jsldata snapshot).

Changes:

  • Capture the last executed SQL in QueryTab and pass export parameters into ResultTabs.
  • Add exportConid/exportDatabase/exportQuery props in ResultTabs and forward them to result grid tabs.
  • Enhance JslDataGridCore export + quick export to use queryReader when export context is provided.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/web/src/tabs/QueryTab.svelte Stores last executed SQL and passes export parameters into result tabs.
packages/web/src/query/ResultTabs.svelte Adds export props and forwards them to JslDataGrid result tabs.
packages/web/src/datagrid/JslDataGridCore.svelte Uses provided export context to export via queryReader (Import/Export + quick export).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/web/src/tabs/QueryTab.svelte
Comment thread packages/web/src/query/ResultTabs.svelte

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 19
{#each resultInfos as info}
<div class="wrapper">
<JslDataGrid jslid={info.jslid} multipleGridsOnTab={resultInfos.length >= 2} />
<JslDataGrid jslid={info.jslid} multipleGridsOnTab={resultInfos.length >= 2} {exportConid} {exportDatabase} {exportQuery} />
</div>

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

AllResultsTab forwards the same exportQuery to each grid. When there are multiple results in this tab, each grid represents a different result set, but query-based export would re-run the same SQL for all of them (likely exporting the wrong result set). Consider only forwarding exportQuery when resultInfos.length === 1, or otherwise omit it so each grid exports from its own jslid.

Copilot uses AI. Check for mistakes.
Comment on lines +151 to +155
} else if (exportQuery && exportConid) {
initialValues.sourceStorageType = 'query';
initialValues.sourceConnectionId = exportConid;
initialValues.sourceDatabaseName = exportDatabase;
initialValues.sourceQuery = exportQuery;

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

When exportQuery is provided, exportGrid() switches to sourceStorageType = 'query', which means exporting will re-execute the SQL coming from the editor. If the last executed statement had side effects (INSERT/UPDATE/DDL, volatile functions, etc.), export could unintentionally run it again. Consider restricting this path to validated read-only queries (single SELECT/WITH) or requiring an explicit user confirmation before using query-based export; otherwise fall back to jsldata.

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +195
const coninfo = await getConnectionInfo({ conid: exportConid });
exportQuickExportFile(
'Query',
{
functionName: 'queryReader',
props: {
...extractShellConnectionHostable(coninfo, exportDatabase),
queryType: 'native',
query: exportQuery,
},
hostConnection: extractShellHostConnection(coninfo, exportDatabase),

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

Quick export uses queryReader with query: exportQuery, which will re-run the editor SQL during export. This has the same side-effect risk as the Import/Export tab path (re-executing non-read-only SQL). Consider only enabling queryReader for validated read-only queries (or after explicit confirmation) and otherwise falling back to jslDataReader.

Suggested change
const coninfo = await getConnectionInfo({ conid: exportConid });
exportQuickExportFile(
'Query',
{
functionName: 'queryReader',
props: {
...extractShellConnectionHostable(coninfo, exportDatabase),
queryType: 'native',
query: exportQuery,
},
hostConnection: extractShellHostConnection(coninfo, exportDatabase),
exportQuickExportFile(
'Query',
{
functionName: 'jslDataReader',
props: {
jslid,
},

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
onOpenChart: () => handleOpenChart(info.resultIndex),
exportConid,
exportDatabase,
exportQuery,
},

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

exportQuery is forwarded into each result tab’s JslDataGrid props. If a single execution produced multiple result sets, exporting from a non-first result would still re-run the same full exportQuery and can export the wrong dataset (and/or re-execute extra statements). Consider only passing exportQuery when there is exactly one result set, or otherwise omit it so export stays tied to the specific jslid for that grid.

Copilot uses AI. Check for mistakes.

This branch has not been deployed

No deployments
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.

2 participants