Son aktif 1729145351

Revizyon 0197dd602abf8582cb458fa31e3994a22d5c2ef6

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