|
| 1 | +import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; |
| 2 | +import { Connection } from "../../../src/connection/Connection"; |
| 3 | +import { EntitySchema } from "../../../src"; |
| 4 | +import { Author, AuthorSchema } from "./entity/Author"; |
| 5 | +import { Post, PostSchema } from "./entity/Post"; |
| 6 | + |
| 7 | +describe("github issues > #1308 Raw Postgresql Update query result is always an empty array", () => { |
| 8 | + let connections: Connection[]; |
| 9 | + before( |
| 10 | + async () => |
| 11 | + (connections = await createTestingConnections({ |
| 12 | + entities: [new EntitySchema<Author>(AuthorSchema), new EntitySchema<Post>(PostSchema)], |
| 13 | + dropSchema: true, |
| 14 | + enabledDrivers: ["postgres"], |
| 15 | + })) |
| 16 | + ); |
| 17 | + beforeEach(() => reloadTestingDatabases(connections)); |
| 18 | + after(() => closeTestingConnections(connections)); |
| 19 | + |
| 20 | + async function prepareData(connection: Connection) { |
| 21 | + const author = new Author(); |
| 22 | + author.id = 1; |
| 23 | + author.name = "Jane Doe"; |
| 24 | + await connection.manager.save(author); |
| 25 | + } |
| 26 | + |
| 27 | + it("Update query returns the number of affected rows", () => |
| 28 | + Promise.all( |
| 29 | + connections.map(async connection => { |
| 30 | + await prepareData(connection); |
| 31 | + |
| 32 | + const result1 = await connection.createQueryBuilder() |
| 33 | + .update(Author) |
| 34 | + .set({ name: "John Doe" }) |
| 35 | + .where("name = :name", { name: "Jonas Doe" }) |
| 36 | + .execute(); |
| 37 | + |
| 38 | + result1.affected!.should.be.eql(0); |
| 39 | + |
| 40 | + const result2 = await connection.createQueryBuilder() |
| 41 | + .update(Author) |
| 42 | + .set({ name: "John Doe" }) |
| 43 | + .where("name = :name", { name: "Jane Doe" }) |
| 44 | + .execute(); |
| 45 | + |
| 46 | + result2.affected!.should.be.eql(1); |
| 47 | + }) |
| 48 | + )); |
| 49 | +}); |
0 commit comments