mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 04:46:02 +00:00
query parameters #913
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"dbgate-datalib": "^5.0.0-alpha.1",
|
"dbgate-datalib": "^5.0.0-alpha.1",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-sqltree": "^5.0.0-alpha.1",
|
"dbgate-sqltree": "^5.0.0-alpha.1",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
"typescript": "^4.4.3"
|
"typescript": "^4.4.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-sqltree": "^5.0.0-alpha.1",
|
"dbgate-sqltree": "^5.0.0-alpha.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"json-stable-stringify": "^1.0.1",
|
"json-stable-stringify": "^1.0.1",
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"chartjs-adapter-moment": "^1.0.0",
|
"chartjs-adapter-moment": "^1.0.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"dbgate-datalib": "^5.0.0-alpha.1",
|
"dbgate-datalib": "^5.0.0-alpha.1",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-sqltree": "^5.0.0-alpha.1",
|
"dbgate-sqltree": "^5.0.0-alpha.1",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"dbgate-types": "^5.0.0-alpha.1",
|
"dbgate-types": "^5.0.0-alpha.1",
|
||||||
|
|||||||
@@ -199,6 +199,8 @@
|
|||||||
'icon type-null': 'mdi mdi-code-equal',
|
'icon type-null': 'mdi mdi-code-equal',
|
||||||
'icon type-unknown': 'mdi mdi-help-box',
|
'icon type-unknown': 'mdi mdi-help-box',
|
||||||
|
|
||||||
|
'icon at': 'mdi mdi-at',
|
||||||
|
|
||||||
'img ok': 'mdi mdi-check-circle color-icon-green',
|
'img ok': 'mdi mdi-check-circle color-icon-green',
|
||||||
'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green',
|
'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green',
|
||||||
'img alert': 'mdi mdi-alert-circle color-icon-blue',
|
'img alert': 'mdi mdi-alert-circle color-icon-blue',
|
||||||
|
|||||||
39
packages/web/src/modals/QueryParametersModal.svelte
Normal file
39
packages/web/src/modals/QueryParametersModal.svelte
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import FormStyledButton from '../buttons/FormStyledButton.svelte';
|
||||||
|
|
||||||
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
|
|
||||||
|
import getElectron from '../utility/getElectron';
|
||||||
|
import ModalBase from './ModalBase.svelte';
|
||||||
|
import { closeCurrentModal } from './modalTools';
|
||||||
|
|
||||||
|
export let parameterNames;
|
||||||
|
export let parameterValues;
|
||||||
|
export let onExecute;
|
||||||
|
|
||||||
|
const handleSubmit = async e => {
|
||||||
|
closeCurrentModal();
|
||||||
|
onExecute(e.detail);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
closeCurrentModal();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<FormProvider initialValues={parameterValues}>
|
||||||
|
<ModalBase {...$$restProps}>
|
||||||
|
<svelte:fragment slot="header">Edit query parameters</svelte:fragment>
|
||||||
|
|
||||||
|
{#each parameterNames as parameterName, index}
|
||||||
|
<FormTextField label={parameterName} name={parameterName} focused={index == 0} />
|
||||||
|
{/each}
|
||||||
|
<svelte:fragment slot="footer">
|
||||||
|
<FormSubmit value="Run query" on:click={handleSubmit} />
|
||||||
|
<FormStyledButton value="Close" on:click={handleClose} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</ModalBase>
|
||||||
|
</FormProvider>
|
||||||
@@ -86,6 +86,9 @@
|
|||||||
import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte';
|
import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte';
|
||||||
import ToolStripCommandSplitButton from '../buttons/ToolStripCommandSplitButton.svelte';
|
import ToolStripCommandSplitButton from '../buttons/ToolStripCommandSplitButton.svelte';
|
||||||
import { getClipboardText } from '../utility/clipboard';
|
import { getClipboardText } from '../utility/clipboard';
|
||||||
|
import ToolStripDropDownButton from '../buttons/ToolStripDropDownButton.svelte';
|
||||||
|
import { extractQueryParameters, replaceQueryParameters } from 'dbgate-query-splitter';
|
||||||
|
import QueryParametersModal from '../modals/QueryParametersModal.svelte';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let conid;
|
export let conid;
|
||||||
@@ -94,6 +97,33 @@
|
|||||||
|
|
||||||
export const activator = createActivator('QueryTab', false);
|
export const activator = createActivator('QueryTab', false);
|
||||||
|
|
||||||
|
const QUERY_PARAMETER_STYLES = [
|
||||||
|
{
|
||||||
|
value: '',
|
||||||
|
text: '(no parameters)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '?',
|
||||||
|
text: '? (positional)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '@',
|
||||||
|
text: '@variable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: ':',
|
||||||
|
text: ':variable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '$',
|
||||||
|
text: '$variable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '#',
|
||||||
|
text: '#variable',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const tabVisible: any = getContext('tabVisible');
|
const tabVisible: any = getContext('tabVisible');
|
||||||
const timerLabel = useTimerLabel();
|
const timerLabel = useTimerLabel();
|
||||||
|
|
||||||
@@ -179,8 +209,38 @@
|
|||||||
visibleResultTabs = !visibleResultTabs;
|
visibleResultTabs = !visibleResultTabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getParameterSplitterOptions() {
|
||||||
|
if (!queryParameterStyle) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!driver) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...driver.getQuerySplitterOptions('editor'), queryParameterStyle };
|
||||||
|
}
|
||||||
|
|
||||||
async function executeCore(sql, startLine = 0) {
|
async function executeCore(sql, startLine = 0) {
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
|
|
||||||
|
const parameters = extractQueryParameters(sql, getParameterSplitterOptions());
|
||||||
|
|
||||||
|
if (parameters.length > 0) {
|
||||||
|
showModal(QueryParametersModal, {
|
||||||
|
parameterNames: parameters,
|
||||||
|
parameterValues: parameters.reduce((acc, x) => ({ ...acc, [x]: '' }), {}),
|
||||||
|
onExecute: values => {
|
||||||
|
const newSql = replaceQueryParameters(sql, values, getParameterSplitterOptions());
|
||||||
|
executeCoreWithParams(newSql, startLine);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
executeCoreWithParams(sql, startLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeCoreWithParams(sql, startLine = 0) {
|
||||||
if (!sql || !sql.trim()) {
|
if (!sql || !sql.trim()) {
|
||||||
showSnackbarError('Skipped executing empty query');
|
showSnackbarError('Skipped executing empty query');
|
||||||
return;
|
return;
|
||||||
@@ -349,6 +409,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
|
let queryParameterStyle = ':';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolStripContainer bind:this={domToolStrip}>
|
<ToolStripContainer bind:this={domToolStrip}>
|
||||||
@@ -421,6 +482,17 @@
|
|||||||
{#if resultCount == 1}
|
{#if resultCount == 1}
|
||||||
<ToolStripExportButton command="jslTableGrid.export" {quickExportHandlerRef} label="Export result" />
|
<ToolStripExportButton command="jslTableGrid.export" {quickExportHandlerRef} label="Export result" />
|
||||||
{/if}
|
{/if}
|
||||||
|
<ToolStripDropDownButton
|
||||||
|
menu={() =>
|
||||||
|
QUERY_PARAMETER_STYLES.map(param => ({
|
||||||
|
label: param.text,
|
||||||
|
onClick: () => {
|
||||||
|
queryParameterStyle = param.value;
|
||||||
|
},
|
||||||
|
}))}
|
||||||
|
label={QUERY_PARAMETER_STYLES.find(x => x.value == queryParameterStyle)?.text}
|
||||||
|
icon="icon at"
|
||||||
|
/>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</ToolStripContainer>
|
</ToolStripContainer>
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bson": "^6.8.0",
|
"bson": "^6.8.0",
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"is-promise": "^4.0.0",
|
"is-promise": "^4.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async-lock": "^1.2.6",
|
"async-lock": "^1.2.6",
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"tedious": "^18.2.0",
|
"tedious": "^18.2.0",
|
||||||
"webpack": "^5.91.0",
|
"webpack": "^5.91.0",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"antares-mysql-dumper": "^0.0.1",
|
"antares-mysql-dumper": "^0.0.1",
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"mysql2": "^3.11.3",
|
"mysql2": "^3.11.3",
|
||||||
"webpack": "^5.91.0",
|
"webpack": "^5.91.0",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dbgate-plugin-tools": "^1.0.8",
|
"dbgate-plugin-tools": "^1.0.8",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"webpack": "^5.91.0",
|
"webpack": "^5.91.0",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"pg": "^8.11.5",
|
"pg": "^8.11.5",
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"webpack": "^5.91.0",
|
"webpack": "^5.91.0",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"dbgate-plugin-tools": "^1.0.4",
|
"dbgate-plugin-tools": "^1.0.4",
|
||||||
"dbgate-query-splitter": "^4.10.5",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"byline": "^5.0.0",
|
"byline": "^5.0.0",
|
||||||
"webpack": "^5.91.0",
|
"webpack": "^5.91.0",
|
||||||
"webpack-cli": "^5.1.4"
|
"webpack-cli": "^5.1.4"
|
||||||
|
|||||||
@@ -4129,10 +4129,10 @@ dbgate-plugin-xml@^5.0.0-alpha.1:
|
|||||||
resolved "https://registry.yarnpkg.com/dbgate-plugin-xml/-/dbgate-plugin-xml-5.2.7.tgz#0762af51ba6f100e75a63907ea6c679e827c9f7c"
|
resolved "https://registry.yarnpkg.com/dbgate-plugin-xml/-/dbgate-plugin-xml-5.2.7.tgz#0762af51ba6f100e75a63907ea6c679e827c9f7c"
|
||||||
integrity sha512-gBXy4qetf7eJQW6lM01B+OKLnKB8MKesojdYKysD9oZ+YpQCX8Tq7aHJCrN14FiyIDinpX61kmFH1+LGJ2RkxQ==
|
integrity sha512-gBXy4qetf7eJQW6lM01B+OKLnKB8MKesojdYKysD9oZ+YpQCX8Tq7aHJCrN14FiyIDinpX61kmFH1+LGJ2RkxQ==
|
||||||
|
|
||||||
dbgate-query-splitter@^4.10.5:
|
dbgate-query-splitter@^4.11.1:
|
||||||
version "4.10.5"
|
version "4.11.1"
|
||||||
resolved "https://registry.yarnpkg.com/dbgate-query-splitter/-/dbgate-query-splitter-4.10.5.tgz#bef9f2c2232b14aab6d3a0d490739ad216a1b45b"
|
resolved "https://registry.yarnpkg.com/dbgate-query-splitter/-/dbgate-query-splitter-4.11.1.tgz#8bbf8e1d5bc1dbc7ca43be5cf7b7fa9ac0fed0c7"
|
||||||
integrity sha512-AWcKcU3hbS8rAYrA52bwzdwtLv1llZgJ7Ut8AVPVWm5i38J4EdRFA2nMnx4Y5GLPqA1SRSUFsjBsNWWaHa/BAg==
|
integrity sha512-5qcSRmnTkdZFWy9m7iiE1PtaE0fkwFx0HuUV5M/EjF6susz1DXStg05rWvybK9y7Sgvu5SjQlV1C3cvsEnSNSw==
|
||||||
|
|
||||||
debug@2.6.9, debug@^2.2.0, debug@^2.3.3:
|
debug@2.6.9, debug@^2.2.0, debug@^2.3.3:
|
||||||
version "2.6.9"
|
version "2.6.9"
|
||||||
|
|||||||
Reference in New Issue
Block a user