在javascript中操作数据库中的CQL参数

在javascript中操作数据库中的CQL参数,javascript,Javascript,我将CQL过滤参数作为varchar存储在数据库中,我必须用JavaScript操作该数据库street_desc是javascript中的一个变量。如何动态地将其分配给字符串 输入参数中的任何内容都必须替换cql参数字符串 var street_desc= "whatever"; //input from the user var town_code = "whatever2"; //input from the user var cql_param=

我将CQL过滤参数作为varchar存储在数据库中,我必须用JavaScript操作该数据库
street_desc
是javascript中的一个变量。如何动态地将其分配给字符串

输入参数
中的任何内容都必须替换cql参数字符串

var street_desc= "whatever"; //input from the user
var town_code = "whatever2"; //input from the user
var cql_param= "roadname_gr='street_desc'&towndesc is not null&town_code='town_code'"; //comes from database

var input_params = [street_desc,town_code]; //declare input params to replace the cql string
输出应为:

“roadname\u gr='whatever'&towndesc不为空&town\u code='whatever2'

我所尝试的

var street_desc = "whatever"; //input from the user
var town_code = "whatever2"; //input from the user
var cql_param = "roadname_gr='street_desc'&towndesc is not null&town_code='town_code'"; //comes from database

var input_params = {
    street_desc: street_desc,
    town_code: town_code
}; //declare input params to replace the cql string



for (const [key, value] of Object.entries(input_params)) {
    console.log(`${key}: ${value}`);
    cql_param.replace(key, value);
}

我更新了我的答案,以使用减速机

让cql_param=“roadname\u gr='street\u desc'&towndesc不为空&town\u code=1”;
var street_desc=“无论如何”//用户的输入
var town_code=“whatever2”//用户的输入
变量输入参数=[街道描述,城镇代码];
变量输入参数名称=[“街道描述”,“1”];
设i=0;
常量结果=输入参数减少((ac,c)=>{
返回ac.replace(输入参数名称[i++],c);
},cql_参数)

console.log(result)
我设法解决了它。以下是我所做的: 用我要替换的输入参数声明一个对象。迭代键值对并替换字符串

var street\u desc\u inp=“随便什么”//用户的输入
var town_code_inp=“whatever2”//用户的输入
var cql_param=“roadname\u gr='street\u desc\u inp'&towndesc不为空&town\u code='town\u code\u inp'”//来自数据库
console.log(cql_参数)
var input_params={//声明输入参数以替换cql字符串
街道描述输入:街道描述输入,
城镇代码输入:城镇代码输入
};
for(对象项的常量[键,值](输入参数))
cql_参数=cql_参数替换(键,值);

console.log(cql_param)
替换占位符?占位符必须是动态的,而不是硬编码的。例如,我可以有一个输入参数数组。我会更新我的问题检查我的更新给我这看起来仍然像你想做一个字符串替换。只需使用带有键值对的数组:
{占位符:'street_deesc',value:'whatever'}
这里有一些想法:你试过了吗?我更新了它的我的代码了吗?现在它没有丢失输出仍然不正确。它应该是
“roadname\u gr='whatever'&towndesc不为空&town\u code='whatever2'这些是您要替换的唯一值,还是您没有包括的其他情况更具意义?这些只是示例,现在看来是正确的。但我认为这似乎有点复杂。我将用我目前正在尝试的更简单的方法更新我的问题。