Skip to content

Commit

Permalink
feat(core): respect schema parameter in clientUrl (#4998)
Browse files Browse the repository at this point in the history
Closes #4997
  • Loading branch information
kaionesyan committed Dec 15, 2023
1 parent 5897514 commit 9176ee0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core/src/connections/Connection.ts
Expand Up @@ -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));
Expand All @@ -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 {
Expand Down Expand Up @@ -175,6 +183,7 @@ export interface ConnectionConfig {
user?: string;
password?: string | (() => MaybePromise<string> | MaybePromise<DynamicPassword>);
database?: string;
schema?: string;
}

export type Transaction<T = any> = T;

0 comments on commit 9176ee0

Please sign in to comment.