-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve issue queryBuilder makes different parameter identifiers…
- Loading branch information
Showing
9 changed files
with
146 additions
and
6 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
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
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
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,10 @@ | ||
import { Column, Entity, PrimaryColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class Weather { | ||
@PrimaryColumn() | ||
id: string | ||
|
||
@Column({ type: "float" }) | ||
temperature: 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,70 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { Weather } from "./entity/weather" | ||
import { expect } from "chai" | ||
|
||
describe("github issues > #7308 queryBuilder makes different parameter identifiers for same parameter, causing problems with groupby", () => { | ||
describe("Postgres & cockroachdb", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [Weather], | ||
enabledDrivers: [ | ||
"postgres", | ||
"cockroachdb", | ||
"spanner", | ||
"mssql", | ||
"oracle", | ||
], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})), | ||
) | ||
|
||
beforeEach(() => reloadTestingDatabases(dataSources)) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("should not create different parameters identifiers for the same parameter", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
const [query, parameters] = dataSource | ||
.getRepository(Weather) | ||
.createQueryBuilder() | ||
.select("round(temperature, :floatNumber)") | ||
.addSelect("count(*)", "count") | ||
.groupBy("round(temperature, :floatNumber)") | ||
.setParameters({ floatNumber: 2.4 }) | ||
.getQueryAndParameters() | ||
query.should.not.be.undefined | ||
|
||
if ( | ||
dataSource.driver.options.type === "postgres" || | ||
dataSource.driver.options.type === "cockroachdb" | ||
) { | ||
expect(query).to.equal( | ||
'SELECT round(temperature, $1), count(*) AS "count" FROM "weather" "Weather" GROUP BY round(temperature, $1)', | ||
) | ||
} else if (dataSource.driver.options.type === "spanner") { | ||
expect(query).to.equal( | ||
'SELECT round(temperature, @param0), count(*) AS "count" FROM "weather" "Weather" GROUP BY round(temperature, @param0)', | ||
) | ||
} else if (dataSource.driver.options.type === "oracle") { | ||
expect(query).to.equal( | ||
'SELECT round(temperature, :1), count(*) AS "count" FROM "weather" "Weather" GROUP BY round(temperature, :1)', | ||
) | ||
} else if (dataSource.driver.options.type === "mssql") { | ||
expect(query).to.equal( | ||
'SELECT round(temperature, @0), count(*) AS "count" FROM "weather" "Weather" GROUP BY round(temperature, @0)', | ||
) | ||
} | ||
return parameters.length.should.eql(1) | ||
}), | ||
)) | ||
}) | ||
}) |