20210925(42 Sofの特定の投稿を参照)
2030 ワード
1.学習時間全体
夜09:00から夜11:00まで
2.学習目標
42 StackOverFlow機能を実装し、特定の投稿ページに必要なデータと実装方法を考えます.
3.学習方法
部下とディスコドロが会話
4.次の学習目標
問題ページング機能の追加
5.学習内容の詳細
REST APIドキュメントの修正と問題の投稿を表示するときに、必要なデータを取得する方法
特定の質問に対する投稿の表示
サーバからインポートしたデータ.
DBからインポートする方法
JOINの使用
JOINは、データベース内の複数のテーブルからインポートされたレコードを組み合わせて1つのテーブルまたは結果セットとして表す
結合メソッドの例
Mysql
SELECT *
FROM Markdown.questions Q
INNER JOIN Markdown.users U
ON U.id = Q.userId
INNER JOIN Markdown.questions_hash_tag_hashtag QH
ON QH.questionsId = Q.id
INNER JOIN Markdown.hashtag H
ON H.id = QH.hashtagId
WHERE Q.id = 1
TypeOrm JOINメソッド
const getQuestionDetailPage = async (questionId) => {
const queryRunner = await getQueryRunner();
const queryBuilder = queryRunner.manager
.getRepository(Question)
.createQueryBuilder('question')
.where('question.id = :questionId', { questionId })
.innerJoinAndSelect('question.user', 'user')
.innerJoinAndSelect('question.hashTag', 'hashTag')
.leftJoinAndSelect('question.comment', 'comment')
const questionInfo = await queryBuilder
.disableEscaping()
.getMany();
const queryBuilder2 = queryRunner.manager
.getRepository(Answer)
.createQueryBuilder('answer')
.where('answer.questionId = :questionId', { questionId })
.innerJoinAndSelect('answer.user', 'user')
.leftJoinAndSelect('answer.comment', 'comment')
const answerInfo = await queryBuilder2
.disableEscaping()
.getMany();
return {
questionInfo: questionInfo,
answerInfo: answerInfo
}
}
Reference
この問題について(20210925(42 Sofの特定の投稿を参照)), 我々は、より多くの情報をここで見つけました https://velog.io/@earthkingman/20210925テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol