[英]Returning raw entities from Azure Table Storage in Node.js
我的JavaScript对象/实体看起来像这样:
{
id: 1,
name: 'foo',
timestamp: new Date()
}
我需要传递给Azure TableService的实体看起来像这样:
{
id: { '_': 1, '$': 'Edm.Int32' },
name: { '_': 'foo', '$': 'Edm.String' },
timestamp:{ '_': new Date(), '$': 'Edm.DateTime' },
}
这可以使用entityGenerator
轻松完成,这也是从TableService返回实体的格式。
是否有可能在从表中获取数据时从TableService返回原始值? 我并不需要在我的JavaScript对象上使用所有这些OData类型和元数据 。
我可能需要使用像PropertyResolver这样的东西,但文档很混乱。
尝试使用options
参数怎么样?
tableService.retrieveEntity(tableName, partitionKey, rowKey, {payloadFormat:"application/json;odata=nometadata"}, function(error, result, response) {});
它也可以用于查询:
tableService.queryEntities(tableName, query, null,{payloadFormat:"application/json;odata=nometadata"}, function(error,result, response) {});
为了获得更清洁的json,你可能会采取response.body
而不是result
。
例:
tableService.retrieveEntity(tableName, partitionKey, rowKey, {payloadFormat:"application/json;odata=nometadata"}, function(error, result, response) {
if (!error)
{
var myEntity = response.body;
}
});
您可以使用entityResolver
来实现此目的。
例:
var entityResolver = function(entity) {
var resolvedEntity = {};
for(key in entity) {
resolvedEntity[key] = entity[key]._;
}
return resolvedEntity;
}
var options = {};
options.entityResolver = entityResolver;
tableSvc.retrieveEntity('mytable', 'hometasks', '1', options, function(error, result, response) {
if(!error) {
console.log('result: ', result);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.