Skip to content
/ cosmosR Public
forked from aaron2012r2/cosmosR

Basic functions for interacting with a CosmosDB REST API using the DocumentDB protocols in R

License

Notifications You must be signed in to change notification settings

mapic/cosmosR

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cosmosR

Basic functions in R for simple interactions with a CosmosDB REST API using Document-based storage.

Installation

library('devtools')
install_github('mapic/cosmosR')

Usage

Get all documents from CosmosDB

# import library
library(cosmosR)

# authenticate with CosmosDB container
cosmosAuth("accessKey", "uri", "databaseName", "collectionName")

# get all documents (default: SELECT * FROM c)
data <- cosmosQuery(content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4) 

Query documents from CosmosDB

# import library
library(cosmosR)

# authenticate with CosmosDB container
cosmosAuth("accessKey", "uri", "databaseName", "collectionName")

# example query
sql.full <- "SELECT * FROM c"

# example query: note that with more complicated queries, SELECT * is not allowed, so use SELECT c
sql.full <- 'SELECT c FROM c JOIN samples IN c.samples JOIN tests IN samples.tests WHERE tests.parameter.code = "10112"'

# query with filter, limit results
data <- cosmosQuery(sql.full = sql.full, max.items = 100, content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4)   

Create Document in CosmosDB

You can also create a document, by using the cosmosCreate() function. (Note that the partition key value is required by CosmosDB both as value in argument and as key=value in the document.)

# import library
library(cosmosR)

# authenticate with "lab-orders" container
cosmosAuth("KeyGoesHere", "uri", "dbName", "collName")

# list of keys t
sql_doc <- list(
    id = "unique-id",       # required
    code = "code-1",        # required, must also be added to cosmosCreate() below
    other = "my-value",     # add whatever you want
    more = "more-values"    # add whatever you want
)

# create item in CosmosDB
data <- cosmosCreate(sql.doc = sql_doc, sql.partitionkey_value = "code-1", content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4) 

License

MIT License

Supported by NGI.no.

Based on work by aaron2012r2.

About

Basic functions for interacting with a CosmosDB REST API using the DocumentDB protocols in R

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%