☀️ BE TIL Day 16 0404

JB·2022년 4월 4일
0

CodeCamp BE 02

목록 보기
15/30

⬇️ Main Note
https://docs.google.com/document/d/1mA8ZeM8M8NDSxySrJ1FHBjDn_ETOX3ia5HT_3WO9STc/edit


🌼 Entity

@Entity() // Telling config file that this page is for table building
export class Product {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @JoinColumn() // Column을 가지고 연결하겠다 => 기준이 있는 곳에 join column을 둠 // one to one은 반대로 바뀔 수 있기에 이걸 해줘야함
  @OneToOne(() => ProductSaleslocation) // 1:1 매핑 column => ProductSaleslocation이랑 Product랑 one to one 이야 라고 알려주는 화살표함수
  productSaleslocation: ProductSaleslocation;

  @ManyToOne(() => ProductCategory)
  productCategory: ProductCategory;

  @JoinTable() // 둘 중 한군데만 해줘도 됨
  @ManyToMany(() => ProductTag, (productTags) => productTags.products) // 서로 반대방향에서 찾는법을 알려줘야함
  productTags: ProductTag[];

  // oneToMany는 database에 존재하지 않는 개념임 (typeORM에서 강제로 oneToMany를 만들어주는것일뿐 원래 존재하지 않음)
}

🌼 SQL Query

🌿 Basic


↘️ Starting the SQL inside the database

↘️ Joining two tables with id

↘️ When yiu write update tattoo set name='myFirstTattoo';
=> Error occurs like this. So, there should be a condition for the code to be executed. Only those data that's name is myTattoo: where name = 'myTattoo';.
=> Result: update tattoo set name='myFirstTattoo' where name='myTattoo'


↘️ Organizing multiple table with ordering in category names

🌿 Data Aggregation

group by name => group data in terms of name
order by price desc => sorting the sequence of price from more expensive price
order by price asc => sorting the sequence of price from cheaper price

🌿 SubQuery

: Using Query inside the Query

  • SubQuery that goes after from is called inline view
  • SubQuery that goes after where is called subQuery
  • SubQuery that goes after select is called scalar subQuery

profile
두비두밥밥

0개의 댓글