SQLite3是否在Node.js中准备了语​​句? [英] Does SQLite3 have prepared statements in Node.js?

查看:56
本文介绍了SQLite3是否在Node.js中准备了语​​句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在npm文档中,只有可见的准备好的语句才能插入.这些准备好的语句对选择,更新和删除有效吗?

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

我尝试进行选择,没有 .each 函数,其中的行被回调.任何人都可以做到这一点或拥有指向资源的链接,因为我敢肯定找不到任何东西.

I tried for select, there isn't a .each function where the rows are called back. Anyone been able to do this or have links to resources, cause I can sure as hell unable to find any.

推荐答案

根据 node-sqlite3 API文档,您可以通过几种不同的方式在SQL查询中使用参数:

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"
});

这篇关于SQLite3是否在Node.js中准备了语​​句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆