从Node.js中的Azure表存储返回原始实体

Sch*_*out 3 azure node.js odata azure-table-storage

我的JavaScript对象/实体看起来像这样:

{
  id: 1,
  name: 'foo',
  timestamp: new Date()
}
Run Code Online (Sandbox Code Playgroud)

我需要传递给Azure TableService的实体看起来像这样:

{
  id: { '_': 1, '$': 'Edm.Int32' },
  name: { '_': 'foo', '$': 'Edm.String' },
  timestamp:{ '_': new Date(), '$': 'Edm.DateTime' },
}
Run Code Online (Sandbox Code Playgroud)

这很容易使用entityGenerator,这也是从TableService返回实体的格式.

是否有可能在从表中获取数据时从TableService返回原始值?我并不需要在我的JavaScript对象上使用所有这些OData类型和元数据.

我可能需要使用像PropertyResolver这样的东西,但文档很混乱.

Woj*_*ech 5

如何尝试options参数?

tableService.retrieveEntity(tableName, partitionKey, rowKey, {payloadFormat:"application/json;odata=nometadata"}, function(error, result, response) {});
Run Code Online (Sandbox Code Playgroud)

它也可以用于查询:

tableService.queryEntities(tableName, query, null,{payloadFormat:"application/json;odata=nometadata"}, function(error,result, response) {});
Run Code Online (Sandbox Code Playgroud)

而且让你可能需要清洁JSON response.body代替result.

例:

tableService.retrieveEntity(tableName, partitionKey, rowKey, {payloadFormat:"application/json;odata=nometadata"}, function(error, result, response) {
        if (!error)
        {
            var myEntity = response.body;
        }
});
Run Code Online (Sandbox Code Playgroud)