简体   繁体   English

table_name 如何成为我的帖子查询中的属性?

[英]How can table_name be a property in my post query?

I want this query to be generic on the table_name meaning that there is in my JSON file a new property named "device" which indicates in which table the data will be inserted.我希望这个查询在 table_name 上是通用的,这意味着在我的 JSON 文件中有一个名为“device”的新属性,它指示将在哪个表中插入数据。

the problem is that in my SQL request I can't specify it.问题是在我的 SQL 请求中我无法指定它。 Here is what I tried:这是我尝试过的:

 INSERT INTO ${device} (adc_v, adc_i, acc_axe_x, acc_axe_y, acc_axe_z, temperature, spo2, pa_diastolique, pa_systolique, indice_confiance, received_on, bpm)' +
            'values(${adc_v}, ${adc_i}, ${acc_axe_x}, ${acc_axe_y}, ${acc_axe_z}, ${temperature}, ${spo2}, ${pa_diastolique}, ${pa_systolique}, ${indice_confiance}, ${received_on}, ${bpm})'

here is my JSON on postman:这是我在 postman 上的 JSON:

{
"device": "tag_7z8eq73",
"adc_v": 130,
"adc_i": {{RandomCourant}}, 
"acc_axe_x": {{RandomAccX}}, 
"acc_axe_y": {{RandomAccY}}, 
"acc_axe_z": {{RandomAccZ}}, 
"temperature": {{RandomTemp}}, 
"spo2": {{RandomSpo2}}, 
"pa_diastolique": {{RandomDias}},
"pa_systolique": {{RandomSys}}, 
"indice_confiance": {{RandomIndiceConf}}, 
"received_on": "{{$isoTimestamp}}", 
"bpm": {{RandomBpm}}}

The table name is: tag_7z8eq73表名是:tag_7z8eq73

here is the error that is returned to me:这是返回给我的错误:

error: erreur de syntaxe sur ou près de « 'tag_7z8eq73' »

Looks like I am close to the solution but there is a syntax problem, the quote?看起来我很接近解决方案,但存在语法问题,报价? is my way the right one?我的方法对吗?

const device = req.body.device;
console.log(device)
return db.none('INSERT INTO '+device+' (adc_v, adc_i, acc_axe_x, acc_axe_y, acc_axe_z, temperature, spo2, pa_diastolique, pa_systolique, indice_confiance, received_on, bpm)' +
        'values(${adc_v}, ${adc_i}, ${acc_axe_x}, ${acc_axe_y}, ${acc_axe_z}, ${temperature}, ${spo2}, ${pa_diastolique}, ${pa_systolique}, ${indice_confiance}, ${received_on}, ${bpm})',
        req.body)

try this尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从DML语句获取column_name和table_name? - How to get column_name and table_name from DML statement? 在table_name内的列内编辑列? - Edit column inside column inside table_name? 如何从查询响应中识别表名(Nodejs) - How can I identify table name from query response (Nodejs) 如何按属性名称将我的对象数组分别显示到我的 html 页面的表中 - How to display my Array of Objects into my html page's table , individually, by their property name 如何使用字符串作为 v-model 指令中的属性名称来访问 Vue 组件的数据属性? - How can I access my Vue component's data property using a string as it's property name in a v-model directive? 数组如何用作属性名称? - How can an Array be used as a property name? 如何在Javascript的属性本身中获取属性名称? - How can I get a property name inside the property itself in Javascript? 如何选择带有字符串形式的属性名称的属性? - How can i choose a property with the name of the property in form of a string? 无法使用 axios 将项目发布到我的 DynamoDB 表 - Can't POST item to my DynamoDB table with axios 我可以从sqlite查询字符串中获取表名吗? - can I get the table name from sqlite query string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM