knox / TypeORM-readme-41.sh
0 likes
0 forks
1 files
Last active
1 | +-------------+--------------+----------------------------+ |
2 | | author | |
3 | +-------------+--------------+----------------------------+ |
4 | | id | int(11) | PRIMARY KEY AUTO_INCREMENT | |
5 | | name | varchar(255) | | |
6 | +-------------+--------------+----------------------------+ |
knox / TypeORM-readme-40.ts
0 likes
0 forks
1 files
Last active
1 | import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from "typeorm" |
2 | import { PhotoMetadata } from "./PhotoMetadata" |
3 | import { Author } from "./Author" |
4 | |
5 | @Entity() |
6 | export class Photo { |
7 | /* ... other columns */ |
8 | |
9 | @ManyToOne(() => Author, (author) => author.photos) |
10 | author: Author |
knox / TypeORM-readme-39.ts
0 likes
0 forks
1 files
Last active
1 | import { |
2 | Entity, |
3 | Column, |
4 | PrimaryGeneratedColumn, |
5 | OneToMany, |
6 | JoinColumn, |
7 | } from "typeorm" |
8 | import { Photo } from "./Photo" |
9 | |
10 | @Entity() |
knox / TypeORM-readme-38.ts
0 likes
0 forks
1 files
Last active
1 | import { AppDataSource } from "./index" |
2 | |
3 | // create photo object |
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.isPublished = true |
9 | |
10 | // create photo metadata object |
knox / TypeORM-readme-37.ts
0 likes
0 forks
1 files
Last active
1 | export class Photo { |
2 | // ... other columns |
3 | |
4 | @OneToOne(() => PhotoMetadata, (metadata) => metadata.photo, { |
5 | cascade: true, |
6 | }) |
7 | metadata: PhotoMetadata |
8 | } |
knox / TypeORM-readme-36.ts
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { PhotoMetadata } from "./entity/PhotoMetadata" |
3 | import { AppDataSource } from "./index" |
4 | |
5 | const photos = await AppDataSource.getRepository(Photo) |
6 | .createQueryBuilder("photo") |
7 | .innerJoinAndSelect("photo.metadata", "metadata") |
8 | .getMany() |
knox / TypeORM-readme-35.ts
0 likes
0 forks
1 files
Last active
1 | import { Photo } from "./entity/Photo" |
2 | import { PhotoMetadata } from "./entity/PhotoMetadata" |
3 | import { AppDataSource } from "./index" |
4 | |
5 | const photoRepository = AppDataSource.getRepository(Photo) |
6 | const photos = await photoRepository.find({ |
7 | relations: { |
8 | metadata: true, |
9 | }, |
10 | }) |
knox / TypeORM-readme-34.ts
0 likes
0 forks
1 files
Last active
1 | import { |
2 | Entity, |
3 | Column, |
4 | PrimaryGeneratedColumn, |
5 | OneToOne, |
6 | Relation, |
7 | } from "typeorm" |
8 | import { PhotoMetadata } from "./PhotoMetadata" |
9 | |
10 | @Entity() |
knox / TypeORM-readme-33.ts
0 likes
0 forks
1 files
Last active
1 | import { |
2 | Entity, |
3 | Column, |
4 | PrimaryGeneratedColumn, |
5 | OneToOne, |
6 | JoinColumn, |
7 | Relation, |
8 | } from "typeorm" |
9 | import { Photo } from "./Photo" |
knox / TypeORM-readme-32.ts
0 likes
0 forks
1 files
Last active
1 | import { Entity, Column, PrimaryGeneratedColumn, OneToOne } from "typeorm" |
2 | import { PhotoMetadata } from "./PhotoMetadata" |
3 | |
4 | @Entity() |
5 | export class Photo { |
6 | /* ... other columns */ |
7 | |
8 | @OneToOne(() => PhotoMetadata, (photoMetadata) => photoMetadata.photo) |
9 | metadata: PhotoMetadata |
10 | } |