Node.js-sqlite placeholder

Can you tell me if these considerations are correct? I can use placeholders in a node.js-sqlite query in these 3 ways:

    1)Directly in the function arguments:

          db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2);

          /*first ? is a placeholder and it is replaced with "bar" value 
          before the query is executed

          second ? is a placeholder and it is replaced with 2 value before 
          the query is executed*/

    2)As an array:

          db.run("UPDATE tbl SET name = ? WHERE id = ?", [ "bar", 2 ]);

         /*Second argument passed to db.run function is a parameters array.

         first ? is a placeholder and it is replaced with first array 
         item("bar") before the query is executed

         second ? is a placeholder and it is replaced with second array 
         item(2) before the query is executed*/


3)As an object with named parameters:

          db.run("UPDATE tbl SET name = $name WHERE id = $id", {
              $id: 2,
              $name: "bar"
          });

    //In this case, the second argument of the db.run function is an object.

        /*$name placeholder in the UPDATE query, is replaced with the 
        $name key 
        value("bar") of the object before the query is executed

        $id placeholder in the UPDATE query, is replaced with the $id key 
        value(2) of the object before the query is executed

        placeholder and object key names must be the same.*/

All correct?

Hello :slight_smile: Welcome to the forum!

Yes :slight_smile:

3 Likes