Dernière activité 1729145351

knox a révisé ce gist 1729145351. Aller à la révision

1 file changed, 26 insertions

TypeORM-readme-25.ts(fichier créé)

@@ -0,0 +1,26 @@
1 + import { Photo } from "./entity/Photo"
2 + import { AppDataSource } from "./index"
3 +
4 + const photoRepository = AppDataSource.getRepository(Photo)
5 + const allPhotos = await photoRepository.find()
6 + console.log("All photos from the db: ", allPhotos)
7 +
8 + const firstPhoto = await photoRepository.findOneBy({
9 + id: 1,
10 + })
11 + console.log("First photo from the db: ", firstPhoto)
12 +
13 + const meAndBearsPhoto = await photoRepository.findOneBy({
14 + name: "Me and Bears",
15 + })
16 + console.log("Me and Bears photo from the db: ", meAndBearsPhoto)
17 +
18 + const allViewedPhotos = await photoRepository.findBy({ views: 1 })
19 + console.log("All viewed photos: ", allViewedPhotos)
20 +
21 + const allPublishedPhotos = await photoRepository.findBy({ isPublished: true })
22 + console.log("All published photos: ", allPublishedPhotos)
23 +
24 + const [photos, photosCount] = await photoRepository.findAndCount()
25 + console.log("All photos: ", photos)
26 + console.log("Photos count: ", photosCount)
Plus récent Plus ancien