-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
139 lines (101 loc) · 3.59 KB
/
README.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
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# ws4sql
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/KTH-Library/ws4sql/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of ws4sql is to provide an R client against the `ws4sql` REST API which serves JSON over HTTP.
```{r intro}
#| eval: true
library(ws4sql)
# below we assume a ws4sql server is running locally
# serving http requests against http://localhost:8000/duckserve/
# the url_base parameter can be used to specify any other location of the service
con <- ws4sql_con("http://ducky:duckz@localhost:8000/duckserve", quiet = FALSE)
# to check that the service is up, use:
con |> ws4sql_ping()
# to perform a query against ws4sql (perform a web transaction named "#Q1"), use:
con$quiet <- TRUE
# NB: TODO: fix rectangularization, for now just ...
ws4sql_read(con, statement = "#Q1") |>
getElement("results") |>
purrr::map_dfr("resultSet") |> tidyr::unnest(a)
```
To understand what kind of web transactions are possible, see a small example below in the `duck.yaml` configuration file.
# Running ws4sql server backed by a duckdb database
Usage example with duckdb.
## Installation
Get the software, download and unpack and make executable:
# download
cd ~/bin
wget -O ws4sql.tgz \
https://github.com/proofrock/ws4sqlite/releases/download/v0.17dev5/ws4sql-v0.17dev5-linux-amd64.tar.gz
# install
gunzip ws4sql.tgz && \
tar xvf ws4sql.tar && \
rm ws4sql.tar && \
chmod +x ws4sql
# verify version
ws4sql -version
Or use podman/docker:
docker pull ghcr.io/proofrock/ws4sql:latest
As of writing, the latest version is tagged like this:
docker pull ghcr.io/proofrock/ws4sql:v0.17dev5
Next configure the API - which is defined in a `server.yaml` file.
## Starting a ws4sql server using a yaml file and duckdb
A yaml file that serves an API backed by duckdb can look like this:
```yaml
database:
type: DUCKDB
inMemory: true
id: duckserve
# disableWALMode: true
readOnly: false
auth:
mode: HTTP
byCredentials:
- user: ducky
password: duckz
readOnly: false
#corsOrigin: https://myownsite.com
storedStatements:
- id: Q0
sql: |
select 42
- id: Q1
sql: |
select range(10) as a, 'one-to-ten' as b
- id: Q2
sql: >
from read_csv_auto('https://csvbase.com/kinder/list-of-user-agents')
- id: Q3
sql: |
from read_json_auto('https://api.openalex.org/works/W4388315306')
- id: Q4
sql: |
install tpch; load tpch; call tpch_queries()
initStatements:
- load json
```
Once this file is available and names 'duck.yaml', use it along with this command:
docker run --rm \
-p "8000:8000" \
-v $(pwd)/duck.yaml:/tmp/duck.yaml \
ghcr.io/proofrock/ws4sql:latest \
-port 8000 -db /tmp/duck.yaml
The command starts the server, mounts the configuration file into the containers file system and starts the server with the 'duck.yaml' configuration.
Once running make sure requests work, using for example:
curl -s -X POST \
--user ducky:duckz \
--header 'Content-Type: application/json' \
--data '{"transaction": [{"query": "#Q1" }]}' \
http://localhost:8000/duckserve