由oracledb客户端(nodejs)中的帖子主体选择

问题描述 投票:-1回答:1

我有一个关于在nodejs中使用Oracle数据库的问题。如何从发布请求中按对象执行查询?

我的意思是可以从表单中获得一组不同的参数。

{'name':'foo'} or {'name':'foo', 'surname':'baz'} or {'name':'foo', 'surname':'baz', 'gender':'male'}

在oracledb模块中,我可以查询特定的绑定集

示例

    ....
        connection.execute(
          // The statement to execute
          `SELECT department_id, department_name
           FROM departments
           WHERE department_id = :id`,

          // The "bind value" 180 for the bind variable ":id"
    [180],
....
node.js oracle node-oracledb
1个回答
0
投票

也许有人会帮忙

  var query = `
  select department_id, department_name from departments
  where 
    (department_id = :id_dep or :id_dep is null)
    and 
    (department_name = :name_dep or :name_dep is null)
  `;
  var binds = 
    {id_dep: req.body.id_dep
    ,name_dep: req.body.name_dep}
  ;

© www.soinside.com 2019 - 2024. All rights reserved.