create.ts
1.87 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { expectTypeOf } from 'expect-type'
import { User } from './models/User';
async () => {
const user = await User.create({
id: 123,
firstName: '<first-name>',
}, {
ignoreDuplicates: false,
returning: true,
});
expectTypeOf(user).toEqualTypeOf<User>()
const voidUsers = await Promise.all([
User.create({
id: 123,
firstName: '<first-name>',
}, {
ignoreDuplicates: true,
returning: false,
}),
User.create({
id: 123,
firstName: '<first-name>',
}, {
ignoreDuplicates: true,
returning: true,
}),
User.create({
id: 123,
firstName: '<first-name>',
}, {
ignoreDuplicates: false,
returning: false,
}),
User.create({
id: 123,
firstName: '<first-name>',
}, { returning: false }),
User.create({
id: 123,
firstName: '<first-name>',
}, { ignoreDuplicates: true }),
]);
expectTypeOf(voidUsers).toEqualTypeOf<[void, void, void, void, void]>()
const emptyUsers = await Promise.all([
User.create(),
User.create(undefined),
User.create(undefined, undefined),
]);
expectTypeOf(emptyUsers).toEqualTypeOf<[User, User, User]>()
const partialUser = await User.create({
id: 123,
firstName: '<first-name>',
lastName: '<last-name>',
}, {
fields: ['firstName'],
returning: ['id'],
});
expectTypeOf(partialUser).toEqualTypeOf<User>()
// @ts-expect-error missing attribute
await User.create({
id: 123,
});
await User.create({
id: 123,
firstName: '<first-name>',
// @ts-expect-error unknown attribute
unknown: '<unknown>',
});
};