0

For the code below how can I get the full query Like

INSERT INTO TABLE(.........) VALUES(........);

I can create the function to create command but it would look bad So Is there way of getting the query used here

I have used mysql2/promise

let command = "INSERT INTO users(joined,name,username,profile,DOB,facebookLink,twitterLink,instagramLink,interests,bio) VALUES (?) ;";
    try {
        let userPosted = await (await connection).query(command, userArr);
        if (userPosted[0].affectedRows === 0) {
            return errors.request.NOT_FOUND;
        }
    } catch (err) {
        console.log(command);
        console.log(err);
        return false;
    }
/*
 Suppose for small command like
let command1 = "INSERT INTO tableA(a,b) VALUES(?);
let tableposted = await (await connection).query(command, [1,2]);

Here I want to get the command used in upper query  ↑↑↑↑↑↑
Like INSERT INTO tableA(a,b) VALUES(1,2);


*/

prosach
  • 312
  • 2
  • 14
  • Not sure I got what you're trying to get as an end result. I mean, `command` variable already store this query, and it can be reused. Do you want to create a skeleton of `INSERT` instead? – raina77ow Jul 02 '21 at 10:06
  • Sir, I have edited the question. Added example at last portion. And `command` contains the same string but I want full `QUERY` not `skeleton` – prosach Jul 02 '21 at 10:26

0 Answers0