Node.js での テーブル ストレージ

entity の追加は普通にやるとこんな感じで書けると思いますが、これだとデータ型は全て文字列になります。

 

    1:  var azure = require('azure')
    2:    , nconf = require('nconf')
    3:    , uuid = require('node-uuid');
    4:   
    5:  nconf.env()
    6:   .file({ file: 'config.json'});
    7:   
    8:  var tableName = nconf.get("TABLE_NAME")
    9:    , accountName = nconf.get("STORAGE_NAME")
   10:    , accountKey = nconf.get("STORAGE_KEY");
   11:   
   12:  var client = azure.createTableService(accountName, accountKey);
   13:   
   14:  client.createTableIfNotExists(tableName, function (res, created) {
   15:      var item = {
   16:          name: 'Add Entity',
   17:          category: 'test',
   18:          date: '12/01/2012',
   19:          RowKey: uuid(),
   20:          PartitionKey: 'partition1',
   21:          num: 123
   22:      };
   23:   
   24:      client.insertEntity(tableName, item, null, function () {
   25:          console.log('insert entity');
   26:      });
   27:  });

 

データ型を指定する場合は、2次元ハッシュを使うので、21行目の指定を以下のように行うことで、データ型の指定が可能です。仕様書はないですが、テストコードを見ると記述されています。

 

   21:          num: { '@': { type: 'Edm.Int32' }, '#': 123 }
  
 備忘録ということで…