forked from typeorm/typeorm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect database from connection urls (typeorm#5640)
* fix: respect database from connection urls database names can be defined in the options object. Now also connection urls that contain a database can be used to have the database set in the drivers object. Closes: typeorm#2096 * only disconnect connection if connected. * revert changes. * fix credentials for testing * create connection by lib function * check typeorm config during testing to check whether a mysql database is available Co-authored-by: julius <julius.friedrich@shift-f3.com>
- Loading branch information
1 parent
c768eab
commit 587977f
Showing
3 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
|
||
@Entity() | ||
export class TestEntity { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import "reflect-metadata"; | ||
import { expect } from "chai"; | ||
import { createConnection } from "../../../src"; | ||
import { getTypeOrmConfig } from "../../utils/test-utils"; | ||
|
||
describe("github issues > #2096 [mysql] Database name isn't read from url", () => { | ||
it("should be possible to define a database by connection url for mysql", async () => { | ||
const config = getTypeOrmConfig(); | ||
|
||
// it is important to synchronize here, to trigger EntityMetadataValidator.validate | ||
// that previously threw the error where the database on the driver object was undefined | ||
if (config.find(c => c.name === "mysql" && !c.skip)) { | ||
const connection = await createConnection({ | ||
name: "#2096", | ||
url: "mysql://root:admin@localhost:3306/test", | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
synchronize: true, | ||
type: "mysql" | ||
}); | ||
expect(connection.isConnected).to.eq(true); | ||
await connection.close(); | ||
} | ||
}); | ||
}); |