I'm trying to insert data into an Azure table but everything is converted to strings.
E.g. I'm inserting numbers/booleans
var test={ PartitionKey : '4', RowKey : '2', foo: 4, bar: true };
tableService.insertEntity('mytable', test, ...);
but
tableService.queryEntity('mytable', '4', '2', ...);
returns
{ 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' }
How can I specify a data type?
OK, just saw in the SDK that you can specify the data type with
var test={ PartitionKey : '4', RowKey : '2',
foo: { '@': { type: 'Edm.Int32' }, '#': 4 } };
however are there any helper functions to add the type automatically?
Since the SDK does not appear to contain anything useful I wrote these for now:
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); }
as in
var test={ PartitionKey : '4', RowKey : '2', foo: azInt32(4) };
I don't know why they changed it but starting with 0.6.10 the azType function needs to be replaced:
function azType(type, v) { return { "$": { type: type }, "_": v }; }
According to here, only these 8 types are supported by the Table Service Data Model:
Be careful with id property in your object:
{ PartitionKey : '4', RowKey : '2', id: azInt32(4) };
if you try to do that, error message is not so obvious:
Error inserting : { [Error: [object Object]] code: 'PropertiesNeedValue', message:{ _: 'The values are not specified for all properties in the entity...','$': { 'xml:lang': 'en-US' } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With