TypeORM-readme-24.ts
· 493 B · TypeScript
Bruto
import { Photo } from "./entity/Photo"
import { AppDataSource } from "./index"
const photo = new Photo()
photo.name = "Me and Bears"
photo.description = "I am near polar bears"
photo.filename = "photo-with-bears.jpg"
photo.views = 1
photo.isPublished = true
const photoRepository = AppDataSource.getRepository(Photo)
await photoRepository.save(photo)
console.log("Photo has been saved")
const savedPhotos = await photoRepository.find()
console.log("All photos from the db: ", savedPhotos)
1 | import { Photo } from "./entity/Photo" |
2 | import { AppDataSource } from "./index" |
3 | |
4 | const photo = new Photo() |
5 | photo.name = "Me and Bears" |
6 | photo.description = "I am near polar bears" |
7 | photo.filename = "photo-with-bears.jpg" |
8 | photo.views = 1 |
9 | photo.isPublished = true |
10 | |
11 | const photoRepository = AppDataSource.getRepository(Photo) |
12 | |
13 | await photoRepository.save(photo) |
14 | console.log("Photo has been saved") |
15 | |
16 | const savedPhotos = await photoRepository.find() |
17 | console.log("All photos from the db: ", savedPhotos) |
18 |