Skip to content

Instantly share code, notes, and snippets.

@martijnlentink
Last active August 30, 2019 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnlentink/861a6543cd225daf3ac1e4c442a3ed8e to your computer and use it in GitHub Desktop.
Save martijnlentink/861a6543cd225daf3ac1e4c442a3ed8e to your computer and use it in GitHub Desktop.
let
Base64Encode = (str as text) => Binary.ToText(Text.ToBinary(str, BinaryEncoding.Base64)),
CreateContinuationTokens = (partitionkey as text, rowkey as text) =>
let
tokenPrefix = "1",
combineToken = "!",
encodedPartition = Base64Encode(partitionkey),
encodedRow = Base64Encode(rowkey),
nextPartKey = Text.Combine({tokenPrefix, Text.From(Text.Length(encodedPartition)), encodedPartition}, combineToken),
nextRowKey = Text.Combine({tokenPrefix, Text.From(Text.Length(encodedRow)), encodedRow}, combineToken),
result = [ NextPartitionKey = nextPartKey, NextRowKey = nextRowKey]
in
result,
Func = (url as text, query as record, optional continuationTokens as record) =>
let
queryCombine = if continuationTokens = null then query else Record.Combine({query, continuationTokens}),
result = Json.Document(Web.Contents(url, [ Headers=[Accept="application/json;odata=nometadata"], Query = queryCombine ])),
resultAsList = result[value],
lastInList = List.Last(resultAsList),
tokens = CreateContinuationTokens(lastInList[PartitionKey], lastInList[RowKey]),
resultList = if List.Count(resultAsList) > 1 then List.Combine({resultAsList, RecursiveTableStorage(url, query, tokens)}) else resultAsList
in
resultList
in
Func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment