forked from typeorm/typeorm
/
issue-6266.ts
60 lines (54 loc) · 1.7 KB
/
issue-6266.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
50
51
52
53
54
55
56
57
58
59
60
import "reflect-metadata";
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { Post } from "./entity/Post";
import sinon from "sinon";
import { SelectQueryBuilder } from "../../../src";
import { assert } from "chai";
describe("github issues > #6266 Many identical selects after insert bunch of items", () => {
let connections: Connection[];
const posts: Post[] = [
{
title: "Post 1",
},
{
title: "Post 2",
},
{
title: "Post 3",
},
{
title: "Post 4",
},
];
before(
async () =>
(connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["mysql"],
}))
);
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should execute a single SELECT to get inserted default and generated values of multiple entities", () =>
Promise.all(
connections.map(async (connection) => {
const selectSpy = sinon.spy(
SelectQueryBuilder.prototype,
"select"
);
await connection
.createQueryBuilder()
.insert()
.into(Post)
.values(posts)
.execute();
assert.strictEqual(selectSpy.calledOnce, true);
selectSpy.restore();
})
));
});