-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerying.Rmd
62 lines (48 loc) · 1.33 KB
/
querying.Rmd
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
---
title: "Querying"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{querying}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(ODataQuery)
service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
people_entity <- service$path("People")
```
There are three ways to query data using this package.
### Directly write OData query
The most direct way is to directly write your query in OData.
- Fast
- Can express any query
- You need to sanitize your inputs
- Can be hard to read if mixing with user code
```{R}
people_entity$filter("Concurrency gt 500")
people_entity$filter("Friends/any(f: f/FirstName eq 'John')")
```
### Using `and_query`, `or_query` and `not_query`
- Automatically sanitized
- Easy to read
- Not every query can be written this way
```{R}
people_entity$filter(Concurrency.gt = 500)
people_entity$filter(or_query(Concurrency.lt = 500, Concurrency.gt = 1500))
```
### Using `to_odata`
- Most readable
- Can express any query
- Automatically sanitized, use !! to unquote
- Slower to process than the other options
```{R}
people_entity$filter(to_odata(Concurrency > 500))
name <- 'John'
people_entity$filter(to_odata(Friends$any(f ~ f$FirstName == !!name)))
```