From 448c15c3088e4c1acc052639c5144d403be601a5 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Wed, 11 Sep 2024 08:16:54 +0200 Subject: [PATCH] supportsTransactions driver parameter --- packages/tools/src/driverBase.ts | 6 +++--- packages/types/engines.d.ts | 1 + plugins/dbgate-plugin-mssql/src/frontend/driver.js | 1 + plugins/dbgate-plugin-mysql/src/frontend/drivers.js | 1 + plugins/dbgate-plugin-oracle/src/frontend/driver.js | 1 + plugins/dbgate-plugin-sqlite/src/frontend/driver.js | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index 307146c4..a1620668 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -66,20 +66,20 @@ export const driverBase = { return new this.dumperClass(this, options); }, async script(pool, sql, options: RunScriptOptions) { - if (options?.useTransaction) { + if (options?.useTransaction && this.supportsTransactions) { runCommandOnDriver(pool, this, dmp => dmp.beginTransaction()); } for (const sqlItem of splitQuery(sql, this.getQuerySplitterOptions('script'))) { try { await this.query(pool, sqlItem, { discardResult: true }); } catch (err) { - if (options?.useTransaction) { + if (options?.useTransaction && this.supportsTransactions) { runCommandOnDriver(pool, this, dmp => dmp.rollbackTransaction()); } throw err; } } - if (options?.useTransaction) { + if (options?.useTransaction && this.supportsTransactions) { runCommandOnDriver(pool, this, dmp => dmp.commitTransaction()); } }, diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index 51cfac77..d054e6e1 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -148,6 +148,7 @@ export interface EngineDriver extends FilterBehaviourProvider { profilerChartAggregateFunction?: string; profilerChartMeasures?: { label: string; field: string }[]; isElectronOnly?: boolean; + supportsTransactions?: boolean; collectionSingularLabel?: string; collectionPluralLabel?: string; diff --git a/plugins/dbgate-plugin-mssql/src/frontend/driver.js b/plugins/dbgate-plugin-mssql/src/frontend/driver.js index 748ad1df..9d58bb04 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/driver.js @@ -142,6 +142,7 @@ const driver = { title: 'Microsoft SQL Server', defaultPort: 1433, defaultAuthTypeName: 'tedious', + supportsTransactions: true, // databaseUrlPlaceholder: 'e.g. server=localhost&authentication.type=default&authentication.type.user=myuser&authentication.type.password=pwd&options.database=mydb', getNewObjectTemplates() { diff --git a/plugins/dbgate-plugin-mysql/src/frontend/drivers.js b/plugins/dbgate-plugin-mysql/src/frontend/drivers.js index 570e065c..80e7c686 100644 --- a/plugins/dbgate-plugin-mysql/src/frontend/drivers.js +++ b/plugins/dbgate-plugin-mysql/src/frontend/drivers.js @@ -120,6 +120,7 @@ const mysqlDriverBase = { authTypeLabel: 'Connection mode', defaultAuthTypeName: 'hostPort', defaultSocketPath: '/var/run/mysqld/mysqld.sock', + supportsTransactions: true, getNewObjectTemplates() { return [ diff --git a/plugins/dbgate-plugin-oracle/src/frontend/driver.js b/plugins/dbgate-plugin-oracle/src/frontend/driver.js index 4150c310..b21d1a8c 100644 --- a/plugins/dbgate-plugin-oracle/src/frontend/driver.js +++ b/plugins/dbgate-plugin-oracle/src/frontend/driver.js @@ -97,6 +97,7 @@ const oracleDriver = { // ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field), getQuerySplitterOptions: () => oracleSplitterOptions, readOnlySessions: true, + supportsTransactions: true, databaseUrlPlaceholder: 'e.g. localhost:1521/orcl', diff --git a/plugins/dbgate-plugin-sqlite/src/frontend/driver.js b/plugins/dbgate-plugin-sqlite/src/frontend/driver.js index b804c664..42f91fa2 100644 --- a/plugins/dbgate-plugin-sqlite/src/frontend/driver.js +++ b/plugins/dbgate-plugin-sqlite/src/frontend/driver.js @@ -44,6 +44,7 @@ const driver = { engine: 'sqlite@dbgate-plugin-sqlite', title: 'SQLite', readOnlySessions: true, + supportsTransactions: true, showConnectionField: (field, values) => field == 'databaseFile' || field == 'isReadOnly', showConnectionTab: (field) => false, beforeConnectionSave: (connection) => ({