lak*_*tak 5 azure node.js azure-table-storage
我正在尝试将数据插入Azure表,但所有内容都转换为字符串.
我正在插入数字/布尔值
var test={ PartitionKey : '4', RowKey : '2', foo: 4, bar: true };
tableService.insertEntity('mytable', test, ...);
Run Code Online (Sandbox Code Playgroud)
但
tableService.queryEntity('mytable', '4', '2', ...);
Run Code Online (Sandbox Code Playgroud)
回报
{ 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' }
Run Code Online (Sandbox Code Playgroud)
如何指定数据类型?
好的,只需在SDK中看到您可以指定数据类型
var test={ PartitionKey : '4', RowKey : '2',
foo: { '@': { type: 'Edm.Int32' }, '#': 4 } };
Run Code Online (Sandbox Code Playgroud)
但有没有任何帮助函数自动添加类型?
由于SDK似乎不包含任何有用的东西,我现在写这些:
function azType(type, v) { return { "@": { type: type }, "#": v }; }
function azBool(v) { return azType("Edm.Boolean", v); }
function azBinary(v) { return azType("Edm.Binary", v); }
function azByte(v) { return azType("Edm.Byte", v); }
function azDateTime(v) { return azType("Edm.DateTime", v); }
function azDateTimeOffset(v) { return azType("Edm.DateTimeOffset", v); }
function azDecimal(v) { return azType("Edm.Decimal", v); }
function azDouble(v) { return azType("Edm.Double", v); }
function azGuid(v) { return azType("Edm.Guid", v); }
function azInt64(v) { return azType("Edm.Int64", v); }
function azInt32(v) { return azType("Edm.Int32", v); }
function azInt16(v) { return azType("Edm.Int16", v); }
function azSByte(v) { return azType("Edm.SByte", v); }
function azSingle(v) { return azType("Edm.Single", v); }
function azString(v) { return azType("Edm.String", v); }
function azTime(v) { return azType("Edm.Time", v); }
Run Code Online (Sandbox Code Playgroud)
如在
var test={ PartitionKey : '4', RowKey : '2', foo: azInt32(4) };
Run Code Online (Sandbox Code Playgroud)
我不知道他们为什么改变它但是从0.6.10开始需要更换azType函数:
function azType(type, v) { return { "$": { type: type }, "_": v }; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4213 次 |
| 最近记录: |