There is an API server on node.js express mysql.
The database consists of 4 tables:
твиты, комменты к твиту, хэштеги, твит_хэштег (many-to-many)
Imagine that the client went to the main page, with the client flies a request to receive all the tweets.
Question:
Whether to send him only tweets, and allow him to request the comments of the post himself and on his tags with other requests, or make 3 requests on the server by generating him a response object, ala
[ { id:1, text:"Hello", comments:[], tags:[] } ... ]
In which comments and tweet tags will already be included?
The problem is that I cannot pull out the desired object as above with one query, because it’s like a table of query results, in the query result table, comments and tags are separate queries, and I don’t know how to do it in mysql
SELECT p.*, comments( SELECT * FROM COMMENTS WHERE post_id=p.id ) FROM posts
LEFT JOIN, INNER JOIN
using the necessary keys - Vasily Barbashev