diff --git a/packages/core/src/connections/Connection.ts b/packages/core/src/connections/Connection.ts index 7cc77e1b880f..78fdca524930 100644 --- a/packages/core/src/connections/Connection.ts +++ b/packages/core/src/connections/Connection.ts @@ -97,6 +97,10 @@ export abstract class Connection { this.options.user = ret.user = this.options.user ?? decodeURIComponent(url.username); this.options.password = ret.password = this.options.password ?? decodeURIComponent(url.password); this.options.dbName = ret.database = this.options.dbName ?? decodeURIComponent(url.pathname).replace(/^\//, ''); + + if (this.options.schema || url.searchParams.has('schema')) { + this.options.schema = ret.schema = this.options.schema ?? decodeURIComponent(url.searchParams.get('schema')!); + } } else { const url = new URL(this.config.getClientUrl()); this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname)); @@ -112,8 +116,12 @@ export abstract class Connection { getClientUrl(): string { const options = this.getConnectionOptions(); const url = new URL(this.config.getClientUrl(true)); + const password = options.password ? ':*****' : ''; + const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName() + ? `?schema=${options.schema}` + : ''; - return `${url.protocol}//${options.user}${options.password ? ':*****' : ''}@${options.host}:${options.port}`; + return `${url.protocol}//${options.user}${password}@${options.host}:${options.port}${schema}`; } setMetadata(metadata: MetadataStorage): void { @@ -175,6 +183,7 @@ export interface ConnectionConfig { user?: string; password?: string | (() => MaybePromise | MaybePromise); database?: string; + schema?: string; } export type Transaction = T;