将RAW SQL查询导入server.js
我有三个不同的raw .sql文件,需要使用Promise.all()进行异步执行。 如果我将查询直接写入Connection.query(),则将失去SQL语法,除非我动态地写下它们。如何将这些查询放入不同的函数中,然后将它们导入服务器。一个示例是注释。sql下面
SELECT
b.id
,a.parent_id -- original post id
,b.post_id
,b.user_id
,b.comment
,c.first_name
,c.last_name
,c.user_name
,c.profile_pic
,c.status
,c.profile_status
,c.creation_datetime
,a.creation_datetime as post_at
FROM
tester.posts_master a
LEFT JOIN tester.post_comment_master b on (a.parent_id = b.parent_id) -- get comments to a particular post join also should the post_id here be used to make a join to post_master_table?
LEFT JOIN tester.user_master c on (c.user_id = b.user_id)
我也希望它们成为JSON响应的一部分,因此我如何将所有三个功能以查询的形式加入一个,以便获得一个响应而不是三个响应?
I have three different raw .sql files that need to be executed asynchronously using a promise.all().
If I write the queries directly into connection.query() I lose the SQL syntax unless I write them dynamically. How do I put these queries inside different functions then import them into the server.js? An example is the comments.sql below
SELECT
b.id
,a.parent_id -- original post id
,b.post_id
,b.user_id
,b.comment
,c.first_name
,c.last_name
,c.user_name
,c.profile_pic
,c.status
,c.profile_status
,c.creation_datetime
,a.creation_datetime as post_at
FROM
tester.posts_master a
LEFT JOIN tester.post_comment_master b on (a.parent_id = b.parent_id) -- get comments to a particular post join also should the post_id here be used to make a join to post_master_table?
LEFT JOIN tester.user_master c on (c.user_id = b.user_id)
I would also like them to be part of a json response so how can I join all three functions for the queries into one so as to get back one response instead of three?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论