Última atividade 1729146172

Revisão c208d3de6845e43f6b30b5ae65b12508c71bf56c

TypeORM-readme-38.ts Bruto
1import { AppDataSource } from "./index"
2
3// create photo object
4const photo = new Photo()
5photo.name = "Me and Bears"
6photo.description = "I am near polar bears"
7photo.filename = "photo-with-bears.jpg"
8photo.isPublished = true
9
10// create photo metadata object
11const metadata = new PhotoMetadata()
12metadata.height = 640
13metadata.width = 480
14metadata.compressed = true
15metadata.comment = "cybershoot"
16metadata.orientation = "portrait"
17
18photo.metadata = metadata // this way we connect them
19
20// get repository
21const photoRepository = AppDataSource.getRepository(Photo)
22
23// saving a photo also save the metadata
24await photoRepository.save(photo)
25
26console.log("Photo is saved, photo metadata is saved too.")