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