Importing raw SQL queries into server.js

Viewed 21

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?

0 Answers
Related