Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable returning additional columns with MSSQL (#7864)
- Loading branch information
1 parent
8937fd2
commit e1db48d
Showing
4 changed files
with
103 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column() | ||
text: string; | ||
|
||
} |
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,47 @@ | ||
import "reflect-metadata"; | ||
import {expect} from "chai"; | ||
import {Connection} from "../../../src"; | ||
import {Post} from "./entity/Post"; | ||
import {createTestingConnections, reloadTestingDatabases, closeTestingConnections} from "../../utils/test-utils"; | ||
|
||
describe("github issues > #7100 MSSQL error when user requests additional columns to be returned", () => { | ||
|
||
let connections: Connection[]; | ||
|
||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [Post], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
enabledDrivers: [ "mssql" ] | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should return user requested columns", () => Promise.all(connections.map(async connection => { | ||
const post = new Post(); | ||
post.title = "title"; | ||
post.text = "text" | ||
|
||
await connection.createQueryBuilder() | ||
.insert() | ||
.into(Post) | ||
.values(post) | ||
.returning(["text"]) | ||
.execute(); | ||
|
||
// Locally we have forgotten what text was set to, must re-fetch | ||
post.text = ""; | ||
await connection.createQueryBuilder(Post, "post") | ||
.update() | ||
.set({ title: "TITLE" }) | ||
.returning(["title", "text"]) | ||
.whereEntity(post) | ||
.updateEntity(true) | ||
.execute(); | ||
|
||
expect(post.title).to.be.equal("TITLE") | ||
expect(post.text).to.be.equal("text"); | ||
}))); | ||
}); |