从Node.js中的Azure表存储返回原始实体
我的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对象上的所有这些ODatatypes和元数据 。
我可能需要使用像PropertyResolver的东西,但文档是相当混乱。
你可以使用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); } });
如何尝试使用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; } });
- 当Node应用程序返回一个4xx时,IIS返回500
- 成功将base64映像保存到Azure Blob存储,但blob映像始终损坏/小的白色框
- 如何在Azure AD上使用passport.js和OpenID Connect策略
- 在Azure函数上使用ImageMagick或GraphicsMagick
- 稳定节点JS AMQP 1.0客户端(事件中心)
- AZURE Mobile Service在表插入脚本中转发POST请求
- 无法从本地计算机上的socket.io-client连接到Azure Web App上的socket.io
- 在Node.js Bot服务中实现Redis
- Azure copyBlob Node.js API错误