feat(editor): add global default transaction commit mode

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-08-28 12:37:11 +08:00
1 parent d3a97164aa
commit fdfad88590
17 files changed
+229 -9

No files matched your search

@@ -129,7 +129,7 @@ describe("supportsTransaction", () => {
});
describe("defaultAutoCommitForDbType", () => {
it("defaults query tabs to auto-commit", () => {
it("defaults query tabs to auto-commit unless the user configured manual", () => {
expect(defaultAutoCommitForDbType("oceanbase-oracle")).toBe(true);
expect(defaultAutoCommitForDbType("oracle")).toBe(true);
expect(defaultAutoCommitForDbType("mysql")).toBe(true);
@@ -137,6 +137,25 @@ describe("defaultAutoCommitForDbType", () => {
expect(defaultAutoCommitForDbType("dameng")).toBe(true);
expect(defaultAutoCommitForDbType(undefined)).toBe(true);
});
it("honors the configured default transaction mode", () => {
expect(defaultAutoCommitForDbType("mysql", "manual")).toBe(false);
expect(defaultAutoCommitForDbType("postgres", "manual")).toBe(false);
expect(defaultAutoCommitForDbType("oracle", "manual")).toBe(false);
expect(defaultAutoCommitForDbType("jdbc", "manual")).toBe(false);
expect(defaultAutoCommitForDbType("mysql", "auto")).toBe(true);
expect(defaultAutoCommitForDbType(undefined, "auto")).toBe(true);
});
it("keeps non-transaction databases auto-commit even when manual is configured", () => {
expect(defaultAutoCommitForDbType("redis", "manual")).toBe(true);
expect(defaultAutoCommitForDbType("mongodb", "manual")).toBe(true);
expect(defaultAutoCommitForDbType("sqlite", "manual")).toBe(true);
expect(defaultAutoCommitForDbType("dameng", "manual")).toBe(true);
expect(defaultAutoCommitForDbType("clickhouse", "manual")).toBe(true);
expect(defaultAutoCommitForDbType("oceanbase-oracle", "manual")).toBe(true);
expect(defaultAutoCommitForDbType(undefined, "manual")).toBe(true);
});
});
describe("supportsSqlInListPaste", () => {
@@ -253,7 +253,18 @@ export function supportsTransaction(dbType?: string): boolean {
/**
* Default auto-commit mode when opening a query tab for the given database type.
* Query tabs default to auto-commit; users can explicitly switch to manual transactions.
*
* When the user has configured `manual` as their default, manual mode only applies to
* databases that actually support explicit transaction control — otherwise the tab is
* forced back to auto-commit so it does not start in an unsupported state. (For
* non-transaction databases, `queryStore` also forces auto-commit on first execution,
* but that would leave the new tab's initial state misleading; gating here avoids that.)
*
* The `defaultMode` selector is the user-configured default (Settings > Editor);
* it is supplied by the caller rather than read here so this module stays free of
* any Pinia store dependency.
*/
export function defaultAutoCommitForDbType(_dbType?: string): boolean {
return true;
export function defaultAutoCommitForDbType(dbType: string | undefined, defaultMode: "auto" | "manual" = "auto"): boolean {
if (defaultMode !== "manual") return true;
return !supportsTransaction(dbType);
}
@@ -94,6 +94,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
"continueOnErrorOnBatch",
"clickTableNavigationTarget",
"completionTriggerMode",
"defaultTransactionMode",
] as const satisfies readonly (keyof EditorSettings)[];
export type EditorSettingsDraftKey = (typeof EDITOR_SETTINGS_DRAFT_KEYS)[number];
@@ -106,6 +106,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =
{ id: "editor-theme", category: "editor", titleKey: "settings.theme", targetId: "editor" },
{ id: "editor-font-size", category: "editor", titleKey: "settings.fontSize", targetId: "editor" },
{ id: "editor-execute-mode", category: "editor", titleKey: "settings.executeMode", targetId: "editor" },
{ id: "editor-default-transaction-mode", category: "editor", titleKey: "settings.defaultTransactionMode", descriptionKey: "settings.defaultTransactionModeDescription", targetId: "editor" },
{ id: "editor-execute-all-on-blank-line", category: "editor", titleKey: "settings.executeAllOnBlankLine", descriptionKey: "settings.executeAllOnBlankLineDescription", targetId: "editor" },
{ id: "editor-execution-target", category: "editor", titleKey: "settings.showExecutionTargetPicker", descriptionKey: "settings.showExecutionTargetPickerDescription", targetId: "editor" },
{ id: "editor-run-buttons", category: "editor", titleKey: "settings.showStatementRunButtons", descriptionKey: "settings.showStatementRunButtonsDescription", targetId: "editor" },