【问题标题】:Azure Table Storage: Translate C# to NodeJS - How to use CompareTo?Azure 表存储:将 C# 转换为 NodeJS - 如何使用 CompareTo?
【发布时间】:2017-08-18 12:41:39
【问题描述】:

互联网上有很多关于如何使用 CompareTo 和 Azure 表存储来从 C# 进行子字符串搜索的示例 ,但我找不到任何显示如何在 NodeJS 中执行此操作的内容,并且我尝试将所有语法放在一起只是抛出各种语法或无效的查询存储异常。

谁能告诉我如何做这个网站上的 C# 示例,但来自 NodeJS? https://lifeportal.azurewebsites.net/azure-table-storage-searching-entities-using-query-like-substring-or-left/

string projectIdString = projectId.ToString().ToLower(); // projectId - Guid
string startQuery = projectIdString + "_"; // Our separate symbol
string endQuery = projectIdString + "`"; // Next symbol in ASCII table after "_"

Expression<Func<DynamicTableEntity, bool>> filters = (e.RowKey.CompareTo(startQuery) >= 0 && e.RowKey.CompareTo(endQuery) < 0);
CloudTable table = _storageContext.Table(Tables.Users);

bool result = await DeleteAllEntitiesInBatches(table, filters);
return result;

最明显的是:

const TABLE_NAME = 'MYTABLE';

var azure = require('azure-storage');
var tableService = azure.createTableService();
var query = new azure.TableQuery()
    .where('PartitionKey eq ?', 'MYKEY').and('RowKey.compareTo(\'1-\') ge ?', 0);

tableService.queryEntities(TABLE_NAME, query, null, function(error, result, response) {
    if (!error) {
        // result.entries contains entities matching the query
    }
});

结果:

"An unknown function with name 'RowKey.compareTo' was found. This may also be a key lookup on a navigation property, which is not allowed."

【问题讨论】:

    标签: c# node.js azure-table-storage azure-tablequery


    【解决方案1】:

    您似乎正在尝试使用 StartsWith 查询 RowKey。在 node.js 中,您可以使用运算符 ge(大于或等于)来执行此操作。

    所以你的代码应该是这样的:

    var query = new azure.TableQuery()
        .where('PartitionKey eq ?', 'MYKEY').and('RowKey ge ?', '<starts with substring>');
    

    【讨论】:

    • 谢谢。我不知道为什么我没有看到这个。既然你回复了,这似乎很明显。
    • 我可能说得太早了。这是不正确的,我不想做startsWith,startsWith是直截了当的。当我有一个复合键:KEY1_KEY2 时,我希望能够搜索 KEY2 值。这就是我对使用 CompareTo 引用的链接所做的理解。是否有来自 NodeJS 的 CompareTo 等价物?
    • Arg,也许我一开始就误读了那个例子。它看起来像 LEFT(又名startsWith)
    • 很遗憾,Azure 表存储不支持通配符搜索,例如endsWithcontains 查询。
    猜你喜欢
    • 2015-03-03
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 2017-07-08
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多