Does SQLite3 have prepared statements in Node.js?

前端 未结 2 1167
情书的邮戳
情书的邮戳 2021-02-07 07:35

From the npm docs, only visible prepared statements are for insert. Does these prepared statement work for Select, update, and delete?

I tried for select, there isn\'t

2条回答
  •  没有蜡笔的小新
    2021-02-07 08:33

    According to the node-sqlite3 API documentation, you can use parameters in your SQL queries in several different ways:

    // Directly in the function arguments.
    db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2);
    
    // As an array.
    db.run("UPDATE tbl SET name = ? WHERE id = ?", [ "bar", 2 ]);
    
    // As an object with named parameters.
    db.run("UPDATE tbl SET name = $name WHERE id = $id", {
      $id: 2,
      $name: "bar"
    });
    

提交回复
热议问题