ODataQuery: ODataQuery

Description Details Active bindings Methods See Also Examples

Description

R6 class that represents an OData query

Details

This class has methods to build and navigate OData services:

Active bindings

url

Generate (encoded) url

Methods

Public methods


Method new()

Create a class representing a query.

Usage
ODataQuery$new(
  service,
  .resource = "",
  .query_options = list(),
  httr_args = list()
)
Arguments
service

The url of the endpoint to connect to. This url should not end with backslash.

.resource

Should not be used directly. Use $path() instead.

.query_options

Should not be used directly. Use methods such as $select(), $filter() and $query() instead.

httr_args

Additional parameters to pass to httr::GET

value

Read-only

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")

Method print()

Print query, useful when debugging.

Usage
ODataQuery$print(top = 0, ...)
Arguments
top

Number of records to print.

...

Additional parameters are passed to print

Examples
\dontrun{
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
service$print(10)$path("People")$print()
}

Method path()

Supply path to the resource

Usage
ODataQuery$path(...)
Arguments
...

Components that lead to resource path

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")

Method get()

Query an individual record by ID parameters

Usage
ODataQuery$get(...)
Arguments
...

ID-parameters (named or unnamed)

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
russellwhyte <- people_entity$get("russellwhyte")

Method func()

Path to an OData function

Usage
ODataQuery$func(fname, ...)
Arguments
fname

Name of the function

...

Options passed to retrieve_data

Returns

closure

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
get_nearest_airport <- service$func('GetNearestAirport')
\dontrun{
get_nearest_airport(lat = 33, lon = -118)
}

Method query()

Supply custom query options that do not start with $

Usage
ODataQuery$query(...)
Arguments
...

Named lists where the names are custom query options

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$query(filter = "FirstName eq 'scott'")$url

Method top()

Limit the number of results to n

Usage
ODataQuery$top(n = 10)
Arguments
n

Number of records to return at most

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$top(10)

Method skip()

Skip first few items

Usage
ODataQuery$skip(n = 10)
Arguments
n

Number of items to skip

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$skip(10)

Method select()

Select fields. If not present, all fields are returned.

Usage
ODataQuery$select(...)
Arguments
...

Fields to select

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$select("FirstName", "LastName")

Method filter()

Apply filter to result

Usage
ODataQuery$filter(...)
Arguments
...

Can be a raw odata query or query options. It's recommended to use query options because these will automatically escape parameters. The parameters are passed on to and_query.

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$filter(FirstName.eq = 'Scott')

Method expand()

Expand on expansion properties

Usage
ODataQuery$expand(...)
Arguments
...

Properties to extend on

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$expand("Friends")

Method orderby()

Order results by one or more keys

Usage
ODataQuery$orderby(...)
Arguments
...

Keys to order by. To order in descending order, the key can be prefixed by a negative sign.

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$orderby('Concurrency')
people_entity$orderby('-Concurrency')

Method search()

Search the entity

Usage
ODataQuery$search(s)
Arguments
s

Search string as defined by the endpoint.

Examples
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$search('Boise')

Method compute()

Compute properties

Add additional properties to query computed from other attributes.

Usage
ODataQuery$compute(...)
Arguments
...

Named list of properties to compute

Examples
# Not really supported by this particular service.
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$compute(a = "5 MUL Concurrency")

Method retrieve()

Retrieve data

Usage
ODataQuery$retrieve(count = FALSE, ...)
Arguments
count

Whether to include a count of the total number of records

...

Passed to retrieve_data

Examples
\dontrun{
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$retrieve()
}

Method all()

Retrieve all data pages

Return concatenation of value of all pages

Usage
ODataQuery$all(...)
Arguments
...

Passed to retrieve_all

Examples
\dontrun{
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$all()
people_entity$all(jsonlite_args = list(simplifyVector = False))
}

Method one()

Retrieve individual

Usage
ODataQuery$one(...)
Arguments
...

Passed to retrieve_one

Examples
\dontrun{
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$top(1)$one(default = NA)
}

See Also

and_query() for details.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
## ------------------------------------------------
## Method `ODataQuery$new`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")

## ------------------------------------------------
## Method `ODataQuery$print`
## ------------------------------------------------

## Not run: 
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
service$print(10)$path("People")$print()

## End(Not run)

## ------------------------------------------------
## Method `ODataQuery$path`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")

## ------------------------------------------------
## Method `ODataQuery$get`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
russellwhyte <- people_entity$get("russellwhyte")

## ------------------------------------------------
## Method `ODataQuery$func`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
get_nearest_airport <- service$func('GetNearestAirport')
## Not run: 
get_nearest_airport(lat = 33, lon = -118)

## End(Not run)

## ------------------------------------------------
## Method `ODataQuery$query`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$query(filter = "FirstName eq 'scott'")$url

## ------------------------------------------------
## Method `ODataQuery$top`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$top(10)

## ------------------------------------------------
## Method `ODataQuery$skip`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$skip(10)

## ------------------------------------------------
## Method `ODataQuery$select`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$select("FirstName", "LastName")

## ------------------------------------------------
## Method `ODataQuery$filter`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$filter(FirstName.eq = 'Scott')

## ------------------------------------------------
## Method `ODataQuery$expand`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$expand("Friends")

## ------------------------------------------------
## Method `ODataQuery$orderby`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$orderby('Concurrency')
people_entity$orderby('-Concurrency')

## ------------------------------------------------
## Method `ODataQuery$search`
## ------------------------------------------------

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$search('Boise')

## ------------------------------------------------
## Method `ODataQuery$compute`
## ------------------------------------------------

# Not really supported by this particular service.
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
people_entity$compute(a = "5 MUL Concurrency")

## ------------------------------------------------
## Method `ODataQuery$retrieve`
## ------------------------------------------------

## Not run: 
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$retrieve()

## End(Not run)

## ------------------------------------------------
## Method `ODataQuery$all`
## ------------------------------------------------

## Not run: 
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$all()
people_entity$all(jsonlite_args = list(simplifyVector = False))

## End(Not run)

## ------------------------------------------------
## Method `ODataQuery$one`
## ------------------------------------------------

## Not run: 
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity$top(1)$one(default = NA)

## End(Not run)

ODataQuery documentation built on July 5, 2021, 5:09 p.m.