knox 修订了这个 Gist . 跳至此修订
1 file changed, 18 insertions
TypeORM-readme-2.ts(file created)
@@ -0,0 +1,18 @@ | |||
1 | + | const userRepository = MyDataSource.getRepository(User) | |
2 | + | ||
3 | + | const user = new User() | |
4 | + | user.firstName = "Timber" | |
5 | + | user.lastName = "Saw" | |
6 | + | user.age = 25 | |
7 | + | await userRepository.save(user) | |
8 | + | ||
9 | + | const allUsers = await userRepository.find() | |
10 | + | const firstUser = await userRepository.findOneBy({ | |
11 | + | id: 1, | |
12 | + | }) // find by id | |
13 | + | const timber = await userRepository.findOneBy({ | |
14 | + | firstName: "Timber", | |
15 | + | lastName: "Saw", | |
16 | + | }) // find by firstName and lastName | |
17 | + | ||
18 | + | await userRepository.remove(timber) |
更新
更早