![](/img/trans.png)
[英]Azure Functions - ICollector binding not in resulting function.json
[英]Azure Functions JavaScript function.json route data binding with floats
我正在嘗試通過where子句中帶有float參數的sqlQuery使用JavaScript Azure Function數據綁定到Cosmos DB。
這是來自function.json的綁定定義:
不起作用,我相信不會返回任何結果,因為經緯度被視為字符串:
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "GetLoq/{lat:float}/{lon:float}"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "doc",
"databaseName": "%CosmosDBNAME%",
"collectionName": "%CosmosCollectionNAME%",
"sqlQuery": "SELECT * FROM c where c.location.coordinates = [{lat}, {lon}]",
"connectionStringSetting": "DB",
"direction": "in"
}
]
當我對值進行硬編碼(以進行比較)時可以使用:
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "GetLoq/{lat:float}/{lon:float}"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "doc",
"databaseName": "%CosmosDBNAME%",
"collectionName": "%CosmosCollectionNAME%",
"sqlQuery": "SELECT * FROM c where c.location.coordinates = [36.71, 3.25]",
"connectionStringSetting": "DB",
"direction": "in"
}
]
該查詢不起作用,因為它搜索的是字符串值["36.71", "3.25"]
而不是float。
有一個問題尚未解決。
路由約束允許在HttpTrigger路由屬性上為查詢字符串參數指定數據類型。 這些約束僅用於匹配路線。 使用綁定參數時,數據類型將轉換為字符串。
我們必須創建一個UDF toFloat
(單擊collection> New UDF旁邊的更多選項圖標)以將字符串首先轉換為float。
function stringToFloatUDF(input){
return parseFloat(input);
}
然后使用UDF修改sqlQuery。
"sqlQuery": "SELECT * from c where c.location.coordinates = [udf.toFloat({lat}), udf.toFloat({lon})]",
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.