Last active
November 19, 2017 15:45
-
-
Save milannankov/0445dfff1e2dd376ff5a022134714a8c to your computer and use it in GitHub Desktop.
Azure Table Storage - Query by Reverse Chronological Order with JavaScript
This file contains hidden or 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
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