-
-
Save mlafleur/060394f0562beb87c430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); // Azure SDK | |
var uuid = require('node-uuid'); // Unique ID Library | |
var async = require('async'); // Aync code helper | |
// These values need to be replaced with | |
// actual values from your Azure storage account. | |
// I love you and all but you can't have mine. ;-) | |
var storageAccount = ""; | |
var storageAccessKey = ""; | |
// TableService interfaces with Azure Table Storage for us | |
var tableService = azure.createTableService(storageAccount, storageAccessKey); | |
async.waterfall( | |
[ | |
// Create our table (if it doesn't exist) | |
function(callback) | |
{ | |
tableService.createTableIfNotExists("TestTable1", function(error) | |
{ | |
if (!error) | |
{ | |
callback(null) | |
} | |
}); | |
}, | |
// Insert the first record | |
function(callback) | |
{ | |
var item = { | |
PartitionKey: 'TestItems', | |
RowKey: '1', | |
TextLabel: 'Hello' | |
}; | |
tableService.insertOrReplaceEntity("TestTable1", item, function(error) | |
{ | |
if (!error) | |
{ | |
return callback(null); | |
} | |
}); | |
}, | |
// Insert the second record | |
function(callback) | |
{ | |
var item = { | |
PartitionKey: 'TestItems', | |
RowKey: '2', | |
TextLabel: 'World' | |
}; | |
tableService.insertOrReplaceEntity("TestTable1", item, function(error) | |
{ | |
if (!error) | |
{ | |
return callback(null); | |
} | |
}); | |
}, | |
// Read the value back out of Azure | |
function(callback) | |
{ | |
var query = azure.TableQuery | |
.select() | |
.from('TestTable1') | |
.where('PartitionKey eq ?', 'TestItems'); | |
tableService.queryEntities(query, function(error, entities) | |
{ | |
if(!error) | |
{ | |
var a = entities[0].TextLabel; | |
var b = entities[1].TextLabel; | |
console.log(a + " " + b); | |
} | |
}); | |
} | |
], | |
function(err) | |
{ | |
console.log("Table and records were created"); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment