2012-12-12 37 views
4

我試圖將數據插入到Azure表中,但一切都轉換爲字符串。Azure表存儲只支持字符串作爲數據類型?

E.g.我將數字/布爾

var test={ PartitionKey : '4', RowKey : '2', foo: 4, bar: true }; 
tableService.insertEntity('mytable', test, ...); 

​​

回報

{ 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' } 

我如何可以指定一個數據類型?


OK,只是,你可以指定

var test={ PartitionKey : '4', RowKey : '2', 
    foo: { '@': { type: 'Edm.Int32' }, '#': 4 } }; 

但是否有任何輔助功能自動添加類型的數據類型的SDK看到?

+0

黑客:我發現如果你用正確類型的虛擬對象來種子表(使用htt p://azurestorageexplorer.codeplex.com/或類似的),然後後續插入將被正確鍵入(並且隨後的插入錯誤類型將引發錯誤)。 – JcFx

+0

有趣。我不知道表存儲支持類似於模式的東西。 – laktak

+0

您可以添加更多的字段到一個實體而不會導致錯誤(並且省略現有的字段),但是如果您已經有一個名爲'test'的字段,並且其中包含一個bool,那麼如果您有一個'invalid input'錯誤嘗試將一個字符串(甚至'真')放入該字段。因此創建一個虛擬對象似乎創建了一種隱式模式。 – JcFx

回答

4

由於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); } 

var test={ PartitionKey : '4', RowKey : '2', foo: azInt32(4) }; 

我不知道爲什麼他們改變它,但啓動與0.6.10 azType功能需要更換:

function azType(type, v) { return { "$": { type: type }, "_": v }; } 
1

只有那些8種類型由表服務數據模型支持:

  • Edm.Binary
  • Edm.Boolean
  • Edm.DateTime
  • Edm.Double
  • Edm.Guid
  • Edm.Int32
  • Edm.Int64
  • Edm.String
通過 http://msdn.microsoft.com/en-us/library/windowsazure/dd179338.aspx

,並小心在你的對象id屬性:

{ PartitionKey : '4', RowKey : '2', id: azInt32(4) };

如果您嘗試這樣做,錯誤消息就不那麼明顯了:

Error inserting : { [Error: [object Object]] code: 'PropertiesNeedValue', message:{ _: 'The values are not specified for all properties in the entity...','$': { 'xml:lang': 'en-US' } } }

相關問題