Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何验证用于查询PostgreSQL数据库的字符串?_Sql_Node.js_Postgresql - Fatal编程技术网

如何验证用于查询PostgreSQL数据库的字符串?

如何验证用于查询PostgreSQL数据库的字符串?,sql,node.js,postgresql,Sql,Node.js,Postgresql,我有一个函数,它使用两个参数构造SQL查询:表名、要查询的列和值 如何验证/清理这些参数(表、列、值) 我目前正在导入一个JSON文件,其中包含我的表和它们各自的列,并检查输入的值是否在这个JSON对象中,这似乎有点骇人听闻 编辑: 我知道node postgres不提供卫生服务。但是,我希望能够有可选参数,例如下面示例中的updated_at,而不需要多个字符串查询 这是一个例子: insert("users", { full_name: "John Smith", username:

我有一个函数,它使用两个参数构造SQL查询:表名、要查询的列和值

如何验证/清理这些参数(表、列、值)

我目前正在导入一个JSON文件,其中包含我的表和它们各自的列,并检查输入的值是否在这个JSON对象中,这似乎有点骇人听闻

编辑:


我知道node postgres不提供卫生服务。但是,我希望能够有可选参数,例如下面示例中的updated_at,而不需要多个字符串查询

这是一个例子:

insert("users", {
  full_name: "John Smith",
  username: "jhsmith",
  email: "john.smith@email.com",
  created_at: "2019-08-18 21:26:43.237",
  updated_at: "2020-03-16 07:11:41.379"
});

Generates:

"INSERT INTO users
(full_name,username,email,created_at,updated_at)
VALUES ('John Smith','jhsmith', ...)"

您的Node/Postgres客户端库应该为您处理转义/清理

您是否正在使用
节点postgres
包?然后可以使用参数化查询流:


我希望能够有可选参数,例如示例中的“updated_at”。由于pg要求我显式地枚举参数(使用$1,$2,…),我必须使用多个字符串,这取决于“updated_at”是否为null。您可以运行
explain
(而不是(!)
explain(analyze)
)并查看这是否会产生任何错误