簡體   English   中英

使用azure-storage節點庫獲取屬於分區鍵的最新記錄的最佳方法是什么?

[英]What is the best way to get the latest record belonging to a partition key using the azure-storage node library?

在使用Node中的Azure存儲庫時,有人可以推薦最佳解決方案來獲取屬於分區鍵的最新記錄嗎? 由於沒有.orderBy()選項,最好的方法是什么?

在C#中,我可能會執行以下操作:

var latestRecord = results.OrderByDescending(r => r.Timestamp).FirstOrDefault();

使用此節點庫進行表存儲時,等效項是什么?

我們需要實現自定義比較功能以對結果進行排序。

tableService.queryEntities(tableName, query, null, function(error, result, response) {
  if (!error) {
      var latestRecord = result.entries.sort((a,b)=>{
          return new Date(b.Timestamp._) - new Date(a.Timestamp._);
      })[0])
 }});

結果以Edm類型修飾,因此我們需要b.Timestamp._

Timestamp: { '$': 'Edm.DateTime', _: 2018-10-26T07:32:58.490Z }

如果這種格式令人不快,我們可以從響應中獲取沒有元數據的實體。 需要設置payloadFormat。

tableService.queryEntities(tableName, query, null, {payloadFormat:azure.TableUtilities.PayloadFormat.NO_METADATA},function(error, result, response) {
  if (!error) {
      var latestRecord = response.body.value.sort((a,b)=>{
          return new Date(b.Timestamp) - new Date(a.Timestamp);
      })[0]
 }});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM