Skip to content

Commit 36f0a78

Browse files
committed
fix typeorm test.ts according to Review
1 parent d7f1e19 commit 36f0a78

File tree

2 files changed

+92
-95
lines changed

2 files changed

+92
-95
lines changed
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
| test.ts:19:20:19:50 | "user.f ... rstName |
22
| test.ts:20:23:20:51 | "user.l ... astName |
3-
| test.ts:83:30:83:37 | BadInput |
4-
| test.ts:89:31:89:38 | BadInput |
5-
| test.ts:98:29:98:36 | BadInput |
6-
| test.ts:112:29:112:36 | BadInput |
7-
| test.ts:116:13:116:32 | [BadInput, BadInput] |
8-
| test.ts:117:13:117:22 | [BadInput] |
9-
| test.ts:123:32:123:39 | BadInput |
10-
| test.ts:124:16:124:23 | BadInput |
11-
| test.ts:130:16:130:23 | BadInput |
12-
| test.ts:135:29:135:36 | BadInput |
13-
| test.ts:139:17:139:24 | BadInput |
14-
| test.ts:140:16:140:23 | BadInput |
15-
| test.ts:144:47:144:54 | BadInput |
16-
| test.ts:150:66:150:73 | BadInput |
17-
| test.ts:157:16:165:9 | (qb) => ... } |
18-
| test.ts:160:25:160:32 | BadInput |
19-
| test.ts:162:24:162:31 | BadInput |
20-
| test.ts:171:92:171:119 | "User2. ... adInput |
21-
| test.ts:176:17:176:23 | "User2" |
22-
| test.ts:178:16:178:23 | BadInput |
23-
| test.ts:183:51:183:78 | "User2. ... adInput |
24-
| test.ts:186:52:186:59 | BadInput |
25-
| test.ts:188:53:188:62 | "User2.id" |
26-
| test.ts:188:72:188:79 | BadInput |
27-
| test.ts:192:51:192:58 | BadInput |
28-
| test.ts:196:13:198:14 | new Bra ... }) |
29-
| test.ts:197:26:197:33 | BadInput |
30-
| test.ts:197:44:197:51 | BadInput |
31-
| test.ts:200:18:200:25 | BadInput |
32-
| test.ts:200:36:200:43 | BadInput |
33-
| test.ts:205:25:205:32 | BadInput |
34-
| test.ts:211:16:211:23 | BadInput |
35-
| test.ts:213:13:215:14 | new Bra ... }) |
36-
| test.ts:214:26:214:33 | BadInput |
37-
| test.ts:214:44:214:51 | BadInput |
38-
| test.ts:217:13:219:14 | new Not ... }) |
39-
| test.ts:218:26:218:33 | BadInput |
40-
| test.ts:218:44:218:51 | BadInput |
3+
| test.ts:80:30:80:37 | 'id > 5' |
4+
| test.ts:86:31:86:38 | 'id > 5' |
5+
| test.ts:95:29:95:44 | "LastNameToFind" |
6+
| test.ts:109:29:109:44 | "LastNameToFind" |
7+
| test.ts:113:13:113:37 | ["first ... tName"] |
8+
| test.ts:114:13:114:26 | ["externalId"] |
9+
| test.ts:120:33:120:43 | "firstname" |
10+
| test.ts:121:16:121:23 | 'id > 5' |
11+
| test.ts:127:16:127:23 | 'id > 5' |
12+
| test.ts:132:29:132:69 | 'SELECT ... id > 5' |
13+
| test.ts:136:17:136:25 | "name,id" |
14+
| test.ts:137:16:137:23 | "id > 5" |
15+
| test.ts:141:47:141:54 | 'id > 5' |
16+
| test.ts:147:66:147:73 | 'id > 5' |
17+
| test.ts:154:16:162:9 | (qb) => ... } |
18+
| test.ts:157:25:157:33 | "name,id" |
19+
| test.ts:159:24:159:31 | 'id > 5' |
20+
| test.ts:168:92:168:108 | "User2.id =:kind" |
21+
| test.ts:173:17:173:23 | "User2" |
22+
| test.ts:175:16:175:23 | 'id > 5' |
23+
| test.ts:180:51:180:78 | "User2. ... id > 5" |
24+
| test.ts:183:52:183:59 | 'id > 5' |
25+
| test.ts:185:53:185:62 | "User2.id" |
26+
| test.ts:185:72:185:79 | 'id > 5' |
27+
| test.ts:189:51:189:58 | 'id > 5' |
28+
| test.ts:193:13:195:14 | new Bra ... }) |
29+
| test.ts:194:26:194:33 | 'id > 5' |
30+
| test.ts:194:44:194:51 | 'id > 5' |
31+
| test.ts:197:18:197:23 | "name" |
32+
| test.ts:197:34:197:41 | 'id > 5' |
33+
| test.ts:202:25:202:32 | 'id > 5' |
34+
| test.ts:208:16:208:23 | 'id > 5' |
35+
| test.ts:210:13:212:14 | new Bra ... }) |
36+
| test.ts:211:26:211:33 | 'id > 5' |
37+
| test.ts:211:44:211:51 | 'id > 5' |
38+
| test.ts:214:13:216:14 | new Not ... }) |
39+
| test.ts:215:26:215:33 | 'id > 5' |
40+
| test.ts:215:44:215:51 | 'id > 5' |

javascript/ql/test/library-tests/frameworks/TypeOrm/test.ts

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -71,151 +71,148 @@ function makePaginationQuery<T>(q: SelectQueryBuilder<T>): SelectQueryBuilder<T>
7171
}
7272

7373
AppDataSource.initialize().then(async () => {
74-
// NOT OK
75-
const BadInput = "1=1"
76-
7774
// Active record
78-
await UserActiveRecord.findByName(BadInput, "Saw")
79-
75+
await UserActiveRecord.findByName("FirstNameToFind", "LastNameToFind")
76+
8077
// data mapper
8178
const selectQueryBuilder = makePaginationQuery<User>(AppDataSource
8279
.createQueryBuilder(User, "User").select());
83-
selectQueryBuilder.where(BadInput).getMany().then(result => {
80+
selectQueryBuilder.where('id > 5').getMany().then(result => {
8481
console.log(result)
8582
});
86-
83+
8784
const selectQueryBuilder2 = makePaginationQuery<User>(AppDataSource
8885
.createQueryBuilder(User, "User"));
89-
selectQueryBuilder2.where(BadInput).getMany().then(result => {
86+
selectQueryBuilder2.where('id > 5').getMany().then(result => {
9087
console.log(result)
9188
});
92-
89+
9390
const insertQueryBuilder: InsertQueryBuilder<User2> = AppDataSource
9491
.createQueryBuilder(User2, "User2").insert();
9592
insertQueryBuilder.into(User2)
9693
.values({
9794
firstName: "Timber",
98-
lastName: () => BadInput,
95+
lastName: () => "LastNameToFind",
9996
age: 33,
10097
}).execute().then(result => {
101-
console.log(result)
102-
103-
104-
})
105-
98+
console.log(result)
99+
100+
101+
})
102+
106103
AppDataSource
107104
.createQueryBuilder(User2, "User")
108105
.insert()
109106
.into(User2)
110107
.values({
111108
firstName: "Timber",
112-
lastName: () => BadInput,
109+
lastName: () => "LastNameToFind",
113110
age: 33,
114111
})
115112
.orUpdate(
116-
[BadInput, BadInput],
117-
[BadInput],
113+
["firstName", "lastName"],
114+
["externalId"],
118115
)
119116
.getQueryAndParameters()
120-
117+
121118
await AppDataSource.getRepository(User2).createQueryBuilder("user2")
122119
.update(User2)
123-
.set({firstName: () => BadInput, lastName: "Saw2", age: 12})
124-
.where(BadInput,)
120+
.set({ firstName: () => "firstname", lastName: "Saw2", age: 12 })
121+
.where('id > 5')
125122
.execute()
126-
123+
127124
await AppDataSource.getRepository(User2).createQueryBuilder('user2')
128125
.delete()
129126
.from(User2)
130-
.where(BadInput)
127+
.where('id > 5')
131128
.execute()
132-
133-
129+
130+
134131
const queryRunner = AppDataSource.createQueryRunner()
135-
await queryRunner.query(BadInput)
136-
132+
await queryRunner.query('SELECT name,id FROM table1 WHERE id > 5')
133+
137134
await queryRunner.manager
138135
.createQueryBuilder(User2, "User")
139-
.select(BadInput)
140-
.where(BadInput).execute()
141-
136+
.select("name,id")
137+
.where("id > 5").execute()
138+
142139
await AppDataSource
143140
.createQueryBuilder(User, "User")
144-
.innerJoin("User.profile", "profile", BadInput, {
141+
.innerJoin("User.profile", "profile", 'id > 5', {
145142
id: 2,
146143
}).getMany().then(res => console.log(res))
147-
144+
148145
await AppDataSource
149146
.createQueryBuilder(User, "User")
150-
.leftJoinAndMapOne("User.profile", "profile", "profile", BadInput, {
147+
.leftJoinAndMapOne("User.profile", "profile", "profile", 'id > 5', {
151148
id: 2,
152149
}).getMany().then(res => console.log(res))
153-
154-
150+
151+
155152
await AppDataSource
156153
.createQueryBuilder(User2, "User2")
157154
.where((qb) => {
158155
const subQuery = qb
159156
.subQuery()
160-
.select(BadInput)
157+
.select("name,id")
161158
.from(User2, "user2")
162-
.where(BadInput)
159+
.where('id > 5')
163160
.getQuery()
164161
return "User2.id IN " + subQuery
165162
})
166163
.setParameter("registered", true)
167164
.getMany()
168-
169-
165+
166+
170167
// Using repository
171-
let users = await AppDataSource.getRepository(User2).createQueryBuilder("User2").where("User2.id =:kind" + BadInput, {kind: 1}).getMany()
172-
168+
let users = await AppDataSource.getRepository(User2).createQueryBuilder("User2").where("User2.id =:kind", { kind: 1 }).getMany()
169+
173170
// Using DataSource
174171
users = await AppDataSource
175172
.createQueryBuilder()
176173
.select("User2")
177174
.from(User2, "User2")
178-
.where(BadInput, {id: 1})
175+
.where('id > 5', { id: 1 })
179176
.getMany()
180-
177+
181178
// Using entity manager
182179
await AppDataSource.manager
183-
.createQueryBuilder(User2, "User2").where("User2.id =:kind" + BadInput, {kind: '1'}).getMany()
180+
.createQueryBuilder(User2, "User2").where("User2.id =:kind and id > 5", { kind: '1' }).getMany()
184181
await AppDataSource
185182
.createQueryBuilder(User2, "User2")
186-
.leftJoinAndSelect("user.photos", "photo", BadInput).getMany()
183+
.leftJoinAndSelect("user.photos", "photo", 'id > 5').getMany()
187184
await AppDataSource
188-
.createQueryBuilder(User2, "User2").groupBy("User2.id").having(BadInput).getMany()
185+
.createQueryBuilder(User2, "User2").groupBy("User2.id").having('id > 5').getMany()
189186
// orderBy
190187
// it is a little bit restrictive, e.g. sqlite don't support it at all
191188
await AppDataSource
192-
.createQueryBuilder(User2, "User2").where(BadInput, {
189+
.createQueryBuilder(User2, "User2").where('id > 5', {
193190
firstName: "Timber",
194191
})
195192
.where(
196193
new Brackets((qb) => {
197-
qb.where(BadInput).orWhere(BadInput);
194+
qb.where('id > 5').orWhere('id > 5');
198195
})
199196
)
200-
.orderBy(BadInput).orWhere(BadInput).getMany()
201-
197+
.orderBy("name").orWhere('id > 5').getMany()
198+
202199
// relation
203200
AppDataSource.createQueryBuilder().relation(User, "name")
204201
.of(User)
205-
.select().where(BadInput).getMany().then(results => {
206-
console.log(results)
207-
})
208-
202+
.select().where('id > 5').getMany().then(results => {
203+
console.log(results)
204+
})
205+
209206
// Brackets
210207
await AppDataSource.createQueryBuilder(User2, "User2")
211-
.where(BadInput)
208+
.where('id > 5')
212209
.andWhere(
213210
new Brackets((qb) => {
214-
qb.where(BadInput).orWhere(BadInput);
211+
qb.where('id > 5').orWhere('id > 5');
215212
})
216213
).andWhere(
217214
new NotBrackets((qb) => {
218-
qb.where(BadInput).orWhere(BadInput)
215+
qb.where('id > 5').orWhere('id > 5')
219216
}),
220217
).getMany()
221218
}).catch(error => console.log(error))

0 commit comments

Comments
 (0)