• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

질문있습니다.

21.03.23 15:24 작성 조회수 109

0

안녕하세요 제로초님!

db에 데이터 저장할때 아래코드처럼 저장 하고 있습니다.

좀더 효과적인 방법이 있는지 궁금해서 질문을 올립니다.

데이터가 몇개 없을때는 상관없을것 같은데 많을때는 어떤식으로 디비에 저장하면 될까요?

매번 좋은 답변감사합니다.

 const created = await this.productRepository.save({
        title: createProductDto.title,
        company: createProductDto.company,
        description: createProductDto.description,
        name: createProductDto.name,
        phone: createProductDto.phone,
        brokerageConsignment: createProductDto.brokerageConsignment.join(','),
        requiredMaterials: createProductDto.requiredMaterials,
        selectMaterials: createProductDto.selectMaterials,
        comment: createProductDto.comment,
        creativeStaff: createProductDto.creativeStaff,
        genre: JSON.stringify(createProductDto.genre),
        mainAudience: JSON.stringify(createProductDto.mainAudience),
        sizeOfPerformance: createProductDto.sizeOfPerformance,
        castMembers: createProductDto.castMembers,
        changeScenario: createProductDto.changeScenario,
        performanceVideo: createProductDto.performanceVideo,
        plan: createProductDto.planningDocument,
        synopsis: createProductDto.synopsis,
        poster: createProductDto.posterURL,
        pcBackground: createProductDto.pcBackground,
        mobileBackground: createProductDto.mobileBackground,
        performanceInformationURL: createProductDto.performanceInformationURL,
        numberList: JSON.stringify(createProductDto.numberList),
        isCheckInformation: createProductDto.isCheckInformation,
        category: createProductDto.category,
        year: createProductDto.year,
        creativeStaff_total: createProductDto.creativeStaff_total,
        totalTime: createProductDto.runningTime,
        provider: findUser,
        progress: ProgressEnum.INPROGRESS,
        createdAt: new Date(),
        updatedAt: new Date(),
        deletedAt: null,
      });

답변 2

·

답변을 작성해보세요.

0

아 감사합니다.

또 혹시 mysql에 배열을 넣을려고 하니깐 에러가 발생하는거 같아서 JSON.stringify 이런식으로 데이터 형식 치환후에 넣고 있는데 방법이 있을까요?(typeorm)

0

x: createProductDto.x 로 겹치는 부분들이 보이는데요. 이런 것은

this.productRepository.save({
  ...createProductDto,
  나머지안겹치는것들
})

이렇게 하면 줄일 수 있겠습니다.