Skip to content

Commit

Permalink
fix: properly override database url properties (#6247)
Browse files Browse the repository at this point in the history
* fix: properly override database url properties

Closes #4878

* test: add test for overriding url options
  • Loading branch information
Redmega committed Jul 6, 2020
1 parent 0d99b46 commit 0ba2a48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/driver/DriverUtils.ts
Expand Up @@ -28,7 +28,7 @@ export class DriverUtils {
if (buildOptions && buildOptions.useSid) {
urlDriverOptions.sid = parsedUrl.database;
}
return Object.assign({}, options, urlDriverOptions);
return Object.assign({}, urlDriverOptions, options);
}
return Object.assign({}, options);
}
Expand Down
19 changes: 19 additions & 0 deletions test/github-issues/4878/issue-4878.ts
@@ -0,0 +1,19 @@
import { DriverUtils } from "../../../src/driver/DriverUtils";
import { expect } from "chai";

describe("github issues > #4878 URL Connection string not overridden by supplied options", () => {
it("should override url-built options with user-supplied options", () => {
const obj: any = {
username: "user",
password: "password",
host: "host",
database: "database",
port: 8888
};

const url = `postgres://url_user:${obj.password}@${obj.host}:${obj.port}/${obj.database}`;
obj.url = url;
const options = DriverUtils.buildDriverOptions(obj);
expect(options.username).to.eql(obj.username);
});
});

0 comments on commit 0ba2a48

Please sign in to comment.