This commit is contained in:
Hong Ooi 2020-10-18 15:44:40 +11:00
Родитель 47a16a1b27
Коммит 2fabad2e80
3 изменённых файлов: 69 добавлений и 4 удалений

Просмотреть файл

@ -10,6 +10,10 @@ export(azure_table)
export(call_table_endpoint)
export(create_azure_table)
export(delete_azure_table)
export(delete_table_entity)
export(get_table_entity)
export(list_azure_tables)
export(list_table_entities)
export(table_endpoint)
export(update_table_entity)
import(AzureStor)

Просмотреть файл

@ -15,13 +15,13 @@ list_azure_tables.table_endpoint <- function(endpoint, ...)
httr::stop_for_status(res, storage_error_message(res))
heads <- httr::headers(res)
res <- httr::content(res)
val <- c(val, res$value)
if(is.null(heads$`x-ms-continuation-NextTableName`))
break
opts$NextTableName <- heads$`x-ms-continuation-NextTableName`
}
AzureRMR::named_list(lapply(val, function(x) azure_table(endpoint, x$TableName)), "TableName")
AzureRMR::named_list(lapply(val, function(x) azure_table(endpoint, x$TableName)))
}
@ -57,7 +57,7 @@ delete_azure_table.table_endpoint <- function(endpoint, name, confirm=TRUE, ...)
#' @export
delete_azure_table.azure_table <- function(endpoint, ...)
{
delete_azure_table(endpoint$endpoint, endpoint$TableName, ...)
delete_azure_table(endpoint$endpoint, endpoint$name, ...)
}
@ -70,7 +70,7 @@ azure_table <- function(endpoint, ...)
#' @export
azure_table.table_endpoint <- function(endpoint, name, ...)
{
structure(list(endpoint=endpoint, TableName=name), class="azure_table")
structure(list(endpoint=endpoint, name=name), class="azure_table")
}

61
R/table_entity.R Normal file
Просмотреть файл

@ -0,0 +1,61 @@
#' @export
update_table_entity <- function(table, entity, partition_key=entity$PartitionKey, row_key=entity$RowKey, etag=NULL)
{
if(is.character(entity) && jsonlite::validate(entity))
entity <- jsonlite::fromJSON(entity, simplifyDataFrame=FALSE)
path <- sprintf("%s(PartitionKey='%s',RowKey='%s')", table$name, partition_key, row_key)
headers <- if(!is.null(etag))
list(`If-Match`=etag)
else list()
res <- call_table_endpoint(table$endpoint, path, body=entity, headers=headers, http_verb="PUT",
http_status_handler="pass")
httr::stop_for_status(res, storage_error_message(res))
invisible(httr::headers(res)$ETag)
}
#' @export
delete_table_entity <- function(table, partition_key, row_key, etag=NULL)
{
path <- sprintf("%s(PartitionKey='%s',RowKey='%s')", table$name, partition_key, row_key)
if(is.null(etag))
etag <- "*"
headers <- list(`If-Match`=etag)
invisible(call_table_endpoint(table$endpoint, path, headers=headers, http_verb="DELETE"))
}
#' @export
list_table_entities <- function(table, filter=NULL, select=NULL)
{
path <- sprintf("%s()", table$name)
opts <- list(
`$filter`=filter,
`$select`=paste0(select, collapse=",")
)
val <- list()
repeat
{
res <- call_table_endpoint(table$endpoint, path, options=opts, http_status_handler="pass")
heads <- httr::headers(res)
res <- httr::content(res)
val <- c(val, res$value)
if(is.null(heads$`x-ms-continuation-NextPartitionKey`))
break
opts$NextPartitionKey <- heads$`x-ms-continuation-NextPartitionKey`
opts$NextRowKey <- heads$`x-ms-continuation-NextRowKey`
}
val
}
#' @export
get_table_entity <- function(table, partition_key, row_key, select=NULL)
{
path <- sprintf("%s(PartitionKey='%s',RowKey='%s')", table$name, partition_key, row_key)
opts <- list(`$select`=paste0(select, collapse=","))
call_table_endpoint(table$endpoint, path, options=opts)
}