【发布时间】:2021-04-08 16:34:47
【问题描述】:
我正在尝试将数据插入 Azure 表,但所有内容都转换为字符串。
例如我正在插入数字/布尔值
var test={ PartitionKey : '4', RowKey : '2', foo: 4, bar: true };
tableService.insertEntity('mytable', test, ...);
但是
tableService.queryEntity('mytable', '4', '2', ...);
返回
{ id: 'http://127.0.0.1:10002/devstoreaccount1/identid(PartitionKey=\'4\',RowKey=\'2\')',
link: 'identid(PartitionKey=\'4\',RowKey=\'2\')',
updated: '2012-12-12T10:26:44Z',
etag: 'W/"datetime\'2012-12-12T10%3A26%3A44.547Z\'"',
PartitionKey: '4',
RowKey: '2',
Timestamp: '2012-12-12T10:20:44.897Z',
foo: '4',
bar: 'true' }
如何指定数据类型?
好的,刚刚在SDK中看到可以指定数据类型
var test={ PartitionKey : '4', RowKey : '2',
foo: { '@': { type: 'Edm.Int32' }, '#': 4 } };
但是有任何辅助函数可以自动添加类型吗?
【问题讨论】:
-
A hack:我发现如果您使用正确类型的虚拟对象(使用 azurestorageexplorer.codeplex.com 或类似对象)为表播种,则后续插入将被正确键入(以及后续插入类型错误会抛出错误)。
-
有趣。我不知道表存储支持模式之类的东西。
-
您可以向实体添加更多字段而不会导致错误(并忽略现有的),但如果您已经有一个名为“test”的字段,其中包含一个布尔值,您将获得一个
invalid input如果您尝试将字符串(甚至是“真”)放入该字段,则会出错。因此,创建一个虚拟对象似乎创建了一种隐式模式。
标签: node.js azure azure-table-storage