mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 23:26:00 +00:00
Commit/rollback in query editor #1039
This commit is contained in:
1
packages/types/dumper.d.ts
vendored
1
packages/types/dumper.d.ts
vendored
@@ -24,4 +24,5 @@ export interface SqlDumper extends AlterProcessor {
|
|||||||
truncateTable(table: NamedObjectInfo);
|
truncateTable(table: NamedObjectInfo);
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
commitTransaction();
|
commitTransaction();
|
||||||
|
rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
category: 'Query',
|
category: 'Query',
|
||||||
name: 'Begin transaction',
|
name: 'Begin transaction',
|
||||||
icon: 'icon transaction',
|
icon: 'icon transaction',
|
||||||
testEnabled: () => !!getCurrentEditor(),
|
testEnabled: () => getCurrentEditor()?.beginTransactionEnabled(),
|
||||||
onClick: () => getCurrentEditor().beginTransaction(),
|
onClick: () => getCurrentEditor().beginTransaction(),
|
||||||
});
|
});
|
||||||
registerCommand({
|
registerCommand({
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
name: 'Commit transaction',
|
name: 'Commit transaction',
|
||||||
toolbarName: 'Commit',
|
toolbarName: 'Commit',
|
||||||
icon: 'icon commit',
|
icon: 'icon commit',
|
||||||
testEnabled: () => !!getCurrentEditor(),
|
testEnabled: () => getCurrentEditor()?.endTransactionEnabled(),
|
||||||
onClick: () => getCurrentEditor().commitTransaction(),
|
onClick: () => getCurrentEditor().commitTransaction(),
|
||||||
});
|
});
|
||||||
registerCommand({
|
registerCommand({
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
name: 'Rollback transaction',
|
name: 'Rollback transaction',
|
||||||
toolbarName: 'Rollback',
|
toolbarName: 'Rollback',
|
||||||
icon: 'icon rollback',
|
icon: 'icon rollback',
|
||||||
testEnabled: () => !!getCurrentEditor(),
|
testEnabled: () => getCurrentEditor()?.endTransactionEnabled(),
|
||||||
onClick: () => getCurrentEditor().rollbackTransaction(),
|
onClick: () => getCurrentEditor().rollbackTransaction(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -177,6 +177,7 @@
|
|||||||
let intervalId;
|
let intervalId;
|
||||||
let isAiAssistantVisible = isProApp() && localStorage.getItem(`tabdata_isAiAssistantVisible_${tabid}`) == 'true';
|
let isAiAssistantVisible = isProApp() && localStorage.getItem(`tabdata_isAiAssistantVisible_${tabid}`) == 'true';
|
||||||
let domAiAssistant;
|
let domAiAssistant;
|
||||||
|
let isInTransaction = false;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
intervalId = setInterval(() => {
|
intervalId = setInterval(() => {
|
||||||
@@ -219,6 +220,7 @@
|
|||||||
$: {
|
$: {
|
||||||
busy;
|
busy;
|
||||||
sessionId;
|
sessionId;
|
||||||
|
isInTransaction;
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,6 +350,7 @@
|
|||||||
sesid: sessionId,
|
sesid: sessionId,
|
||||||
});
|
});
|
||||||
sessionId = null;
|
sessionId = null;
|
||||||
|
isInTransaction = false;
|
||||||
busy = false;
|
busy = false;
|
||||||
timerLabel.stop();
|
timerLabel.stop();
|
||||||
}
|
}
|
||||||
@@ -403,6 +406,35 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function beginTransaction() {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.beginTransaction();
|
||||||
|
executeCore(dmp.s);
|
||||||
|
isInTransaction = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function beginTransactionEnabled() {
|
||||||
|
return driver?.supportsTransactions && !isInTransaction && !busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function endTransactionEnabled() {
|
||||||
|
return !!sessionId && driver?.supportsTransactions && isInTransaction && !busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function commitTransaction() {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.commitTransaction();
|
||||||
|
executeCore(dmp.s);
|
||||||
|
isInTransaction = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rollbackTransaction() {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.rollbackTransaction();
|
||||||
|
executeCore(dmp.s);
|
||||||
|
isInTransaction = false;
|
||||||
|
}
|
||||||
|
|
||||||
const handleMesageClick = message => {
|
const handleMesageClick = message => {
|
||||||
// console.log('EDITOR', editorRef.current.editor);
|
// console.log('EDITOR', editorRef.current.editor);
|
||||||
if (domEditor.getEditor()) {
|
if (domEditor.getEditor()) {
|
||||||
@@ -628,9 +660,21 @@
|
|||||||
>
|
>
|
||||||
AI Assistant
|
AI Assistant
|
||||||
</ToolStripCommandButton>
|
</ToolStripCommandButton>
|
||||||
<ToolStripCommandButton command="query.beginTransaction" data-testid="QueryTab_beginTransactionButton" />
|
<ToolStripCommandButton
|
||||||
<ToolStripCommandButton command="query.commitTransaction" data-testid="QueryTab_commitTransactionButton" />
|
command="query.beginTransaction"
|
||||||
<ToolStripCommandButton command="query.rollbackTransaction" data-testid="QueryTab_rollbackTransactionButton" />
|
data-testid="QueryTab_beginTransactionButton"
|
||||||
|
hideDisabled
|
||||||
|
/>
|
||||||
|
<ToolStripCommandButton
|
||||||
|
command="query.commitTransaction"
|
||||||
|
data-testid="QueryTab_commitTransactionButton"
|
||||||
|
hideDisabled
|
||||||
|
/>
|
||||||
|
<ToolStripCommandButton
|
||||||
|
command="query.rollbackTransaction"
|
||||||
|
data-testid="QueryTab_rollbackTransactionButton"
|
||||||
|
hideDisabled
|
||||||
|
/>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</ToolStripContainer>
|
</ToolStripContainer>
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ const dialect = {
|
|||||||
|
|
||||||
const postgresDriverBase = {
|
const postgresDriverBase = {
|
||||||
...driverBase,
|
...driverBase,
|
||||||
|
supportsTransactions: true,
|
||||||
dumperClass: Dumper,
|
dumperClass: Dumper,
|
||||||
dialect,
|
dialect,
|
||||||
// showConnectionField: (field, values) =>
|
// showConnectionField: (field, values) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user