diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index 9037df9b..76d2dc20 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -16,6 +16,7 @@ const dialect = { isSparse: false, isPersisted: false, }, + defaultSchemaName: null, }; export const driverBase = { diff --git a/packages/types/dialect.d.ts b/packages/types/dialect.d.ts index 70b241f1..a8a1b237 100644 --- a/packages/types/dialect.d.ts +++ b/packages/types/dialect.d.ts @@ -9,6 +9,7 @@ export interface SqlDialect { fallbackDataType?: string; explicitDropConstraint?: boolean; anonymousPrimaryKey?: boolean; + defaultSchemaName?: string; enableConstraintsPerTable?: boolean; dropColumnDependencies?: string[]; diff --git a/packages/web/src/appobj/DatabaseObjectAppObject.svelte b/packages/web/src/appobj/DatabaseObjectAppObject.svelte index b13cabf6..a6cceab6 100644 --- a/packages/web/src/appobj/DatabaseObjectAppObject.svelte +++ b/packages/web/src/appobj/DatabaseObjectAppObject.svelte @@ -9,7 +9,7 @@ schemaName, ...(columns?.map(({ columnName }) => ({ childName: columnName })) || []) ); - export const createTitle = ({ pureName }) => pureName; + export const createTitle = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName); export const databaseObjectIcons = { tables: 'img table', @@ -586,6 +586,16 @@ } } + function getObjectTitle(connection, schemaName, pureName) { + const driver = findEngineDriver(connection, getExtensions()); + + const defaultSchema = driver?.dialect?.defaultSchemaName; + if (schemaName && defaultSchema && schemaName != defaultSchema) { + return `${schemaName}.${pureName}`; + } + return pureName; + } + export async function openDatabaseObjectDetail( tabComponent, scriptTemplate, @@ -603,7 +613,7 @@ openNewTab( { - title: scriptTemplate ? 'Query #' : pureName, + title: scriptTemplate ? 'Query #' : getObjectTitle(connection, schemaName, pureName), tooltip, icon: icon || (scriptTemplate ? 'img sql-file' : databaseObjectIcons[objectTypeField]), tabComponent: scriptTemplate ? 'QueryTab' : tabComponent, diff --git a/plugins/dbgate-plugin-mssql/src/frontend/driver.js b/plugins/dbgate-plugin-mssql/src/frontend/driver.js index ae1b15c7..7e13dfa4 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/driver.js @@ -10,6 +10,7 @@ const dialect = { rangeSelect: true, offsetFetchRangeSyntax: true, rowNumberOverPaging: true, + defaultSchemaName: 'dbo', stringEscapeChar: "'", fallbackDataType: 'nvarchar(max)', explicitDropConstraint: false, diff --git a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js index fe1c8887..3c1ac062 100644 --- a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js +++ b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js @@ -8,6 +8,7 @@ const spatialTypes = ['GEOGRAPHY']; const dialect = { rangeSelect: true, ilike: true, + defaultSchemaName: 'public', // stringEscapeChar: '\\', stringEscapeChar: "'", fallbackDataType: 'varchar',