将RAW SQL查询导入server.js

发布于 2025-02-11 18:27:40 字数 770 浏览 0 评论 0原文

我有三个不同的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文