knox / TypeORM-readme-31.ts
0 likes
0 forks
1 files
Last active
1 | import { |
2 | Entity, |
3 | Column, |
4 | PrimaryGeneratedColumn, |
5 | OneToOne, |
6 | JoinColumn, |
7 | } from "typeorm" |
8 | import { Photo } from "./Photo" |
9 | |
10 | @Entity() |
knox / TypeORM-readme-30.sh
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { PhotoMetadata } from "./entity/PhotoMetadata" |
3 | |
4 | // create a photo |
5 | const photo = new Photo() |
6 | photo.name = "Me and Bears" |
7 | photo.description = "I am near polar bears" |
8 | photo.filename = "photo-with-bears.jpg" |
9 | photo.views = 1 |
10 | photo.isPublished = true |
knox / TypeORM-readme-29.sh
0 likes
0 forks
1 files
Last active
1 | +-------------+--------------+----------------------------+ |
2 | | photo_metadata | |
3 | +-------------+--------------+----------------------------+ |
4 | | id | int(11) | PRIMARY KEY AUTO_INCREMENT | |
5 | | height | int(11) | | |
6 | | width | int(11) | | |
7 | | comment | varchar(255) | | |
8 | | compressed | boolean | | |
9 | | orientation | varchar(255) | | |
10 | | photoId | int(11) | FOREIGN KEY | |
knox / TypeORM-readme-28.ts
0 likes
0 forks
1 files
Last active
1 | import { |
2 | Entity, |
3 | Column, |
4 | PrimaryGeneratedColumn, |
5 | OneToOne, |
6 | JoinColumn, |
7 | } from "typeorm" |
8 | import { Photo } from "./Photo" |
9 | |
10 | @Entity() |
knox / TypeORM-readme-27.ts
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { AppDataSource } from "./index" |
3 | |
4 | const photoRepository = AppDataSource.getRepository(Photo) |
5 | const photoToRemove = await photoRepository.findOneBy({ |
6 | id: 1, |
7 | }) |
8 | await photoRepository.remove(photoToRemove) |
knox / TypeORM-readme-26.ts
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { AppDataSource } from "./index" |
3 | |
4 | const photoRepository = AppDataSource.getRepository(Photo) |
5 | const photoToUpdate = await photoRepository.findOneBy({ |
6 | id: 1, |
7 | }) |
8 | photoToUpdate.name = "Me, my friends and polar bears" |
9 | await photoRepository.save(photoToUpdate) |
knox / TypeORM-readme-25.ts
0 likes
0 forks
1 files
Last active
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 | }) |
knox / TypeORM-readme-24.ts
0 likes
0 forks
1 files
Last active
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 |
knox / TypeORM-readme-23.ts
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { AppDataSource } from "./index" |
3 | |
4 | const savedPhotos = await AppDataSource.manager.find(Photo) |
5 | console.log("All photos from the db: ", savedPhotos) |
knox / TypeORM-readme-22.ts
0 likes
0 forks
1 files
Last active
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 |