Skip to content

Instantly share code, notes, and snippets.

@milannankov
Last active November 19, 2017 15:45
Show Gist options
  • Save milannankov/0445dfff1e2dd376ff5a022134714a8c to your computer and use it in GitHub Desktop.
Save milannankov/0445dfff1e2dd376ff5a022134714a8c to your computer and use it in GitHub Desktop.
Azure Table Storage - Query by Reverse Chronological Order with JavaScript
const uuidv4 = require('uuid/v4');
const moment = require('moment');
module.exports = function (context, req) {
// Save Table storage entry
context.bindings.tableEntry = {
PartitionKey: 'myPartition',
RowKey: GenerateKey(),
Text: "sample"
}
context.done();
};
function GenerateKey() {
let inverted = getInvertedTimestamp();
let uid = uuidv4();
return inverted + '_' + uid;
}
function getInvertedTimestamp() {
let inverted = moment('3000-01-01').unix() - moment().unix();
let invertedString = inverted.toString();
let pad = "000000000000000";
return pad.substring(0, pad.length - invertedString.length) + invertedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment