Skip to content

Commit f122a24

Browse files
committed
Expand tooling documentation
1 parent 0868fb0 commit f122a24

25 files changed

Lines changed: 392 additions & 53 deletions

doc/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ doc/
1717
│ ├── first_plot.qmd Tutorial: first visualization
1818
│ ├── grammar.qmd Grammar of Graphics conceptual foundation
1919
│ ├── anatomy.qmd Anatomy of a ggsql query
20-
│ ├── tooling.qmd VS Code / Positron / Jupyter / Python / R / CLI integrations
20+
│ ├── tooling/ VS Code / Positron / Jupyter / Python / R / CLI / Wasm
2121
│ └── the_rest.qmd Advanced features
2222
├── syntax/
2323
│ ├── index.qmd

doc/_quarto.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,22 @@ website:
139139
href: get_started/grammar.qmd
140140
- text: Anatomy of ggsql
141141
href: get_started/anatomy.qmd
142-
- text: Tooling
143-
href: get_started/tooling.qmd
142+
- section: Tooling
143+
contents:
144+
- text: Overview
145+
href: get_started/tooling/index.qmd
146+
- text: Positron / VS Code
147+
href: get_started/tooling/positron-vscode.qmd
148+
- text: Jupyter & Quarto
149+
href: get_started/tooling/jupyter-quarto.qmd
150+
- text: CLI
151+
href: get_started/tooling/cli.qmd
152+
- text: Python
153+
href: get_started/tooling/python.qmd
154+
- text: R
155+
href: get_started/tooling/r.qmd
156+
- text: WebAssembly
157+
href: get_started/tooling/webassembly.qmd
144158
- text: The rest of the owl
145159
href: get_started/the_rest.qmd
146160
- text: Wrap up

doc/assets/logos/javascript.svg

Lines changed: 4 additions & 0 deletions
Loading

doc/assets/logos/webassembly.svg

Lines changed: 8 additions & 0 deletions
Loading

doc/get_started/installation.qmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,16 @@ ggsql-jupyter --install
284284

285285
For syntax highlighting and language support in VS Code or Positron, install the ggsql extension. You can either install it directly from the [extension marketplace](https://open-vsx.org/extension/ggsql/ggsql) from within the IDE or download and install it manually (in the *Extensions* view, click the `...` menu, select "Install from VSIX...", and choose the downloaded file.)
286286
:::
287+
288+
::: {.icon-section}
289+
[![](../assets/logos/webassembly.svg){height=60} ![](../assets/logos/javascript.svg){height=60}]{.section-icons}
290+
291+
## WebAssembly / JavaScript
292+
293+
To use ggsql in a web application or JavaScript environment, you can install the `ggsql-wasm` package from [npm](https://www.npmjs.com/package/ggsql-wasm):
294+
295+
```bash
296+
npm install ggsql-wasm
297+
```
298+
299+
:::

doc/get_started/tooling.qmd

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sidebar: get_started
2+
page-navigation: true

doc/get_started/tooling/cli.qmd

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Command line interface
3+
---
4+
5+
The `ggsql` command line interface lets you execute queries and validate syntax directly from the terminal. While it may not be the most ergonomic way to interact directly with ggsql, it is useful for scripting, automation, and building tools around ggsql.
6+
7+
## Installation
8+
9+
Install the ggsql CLI on your system using the standard [installation instructions](../installation.html).
10+
11+
## Executing a query
12+
13+
You can execute a ggsql query from a string with `ggsql exec`:
14+
15+
```bash
16+
ggsql exec "VISUALISE species AS fill FROM ggsql:penguins DRAW bar"
17+
```
18+
19+
Or run a `.gsql` file:
20+
21+
```bash
22+
ggsql run my_query.gsql
23+
```
24+
25+
In both cases, output is written to `stdout` as a Vega-Lite JSON spec. You can redirect it to a file:
26+
27+
```bash
28+
ggsql run my_query.gsql > chart.vl.json
29+
```
30+
31+
Such files can be rendered as images using tools that work with Vega-Lite specs, such the [Online Vega Editor](https://vega.github.io/editor/) or [vl-convert](https://github.com/vega/vl-convert) command line tool. For example,
32+
33+
```bash
34+
vl-convert vl2png -i chart.vl.json -o chart.png
35+
```
36+
37+
A standard SQL query can also be provided to ggsql. If the query returns a table, the resulting values will be written to `stdout`.
38+
39+
## Validating a query
40+
41+
If you only want to check that a query is syntactically valid without executing it, use `ggsql validate`:
42+
43+
```bash
44+
$ ggsql validate "VISUALISE x, y FROM table DRAW point"
45+
✓ Query syntax is valid
46+
```
47+
48+
## Database connections
49+
50+
Both `ggsql exec` and `ggsql run` accept a `--reader` flag that can be used to specify a connection string to be used when executing the query. If not provided, ggsql will use an empty in-memory duckdb connection, equivalent to `--reader duckdb://memory`.
51+
52+
```bash
53+
$ ggsql exec --reader sqlite://sample/ggsql_test.sqlite \
54+
"SELECT * FROM test_table LIMIT 3"
55+
col_a, col_b, col_c
56+
215.87, 75.11, delta
57+
418.78, 71.75, delta
58+
495.75, 12.55, delta
59+
60+
$ ggsql exec --reader odbc://DSN=ggsql-pg-test \
61+
"SELECT * FROM test_table LIMIT 3"
62+
col_a, col_b, col_c
63+
319.34, 91.45, gamma
64+
299.08, 49.36, epsilon
65+
12.5, 29.48, gamma
66+
```
67+
68+
## Documentation
69+
70+
The ggsql CLI has built-in documentation for ggsql syntax and usage. Run `ggsql docs` for an overview of available documentation topics, and `ggsql docs [topic]` to read about a specific topic.
71+
72+
```bash
73+
$ ggsql docs draw
74+
DRAW is perhaps the most important clause in ggsql as it defines a layer in your
75+
visualisation. A layer is a single instance of a visual representation of a dataset.
76+
[...]
77+
```
78+
79+
A ggsql skill, a usage guide intended for AI assistants and humans, can also be output using the `ggsql skill` command.
80+
81+
```bash
82+
$ ggsql skill
83+
ggsql Query Writer
84+
ggsql is a SQL extension for declarative data visualization based on
85+
Grammar of Graphics principles.
86+
[...]
87+
```

doc/get_started/tooling/index.qmd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Tooling
3+
---
4+
5+
Now that we understand some of the most important parts of the syntax let's spend a bit of time on where and how to apply it. All the examples on this website are interactive and run directly in the browser, which is obviously useful for teaching, but it will not suffice for your day-to-day work where you need to interact with your own data. ggsql is a general tool you can use in a multitude of ways and we'll go over them in this section.
6+
7+
- **[Positron / VS Code](positron-vscode.qmd)** --- Full language support in your IDE with syntax highlighting, autocomplete, and an integrated REPL.
8+
9+
- **[Jupyter & Quarto](jupyter-quarto.qmd)** --- Use ggsql as a kernel in Jupyter or Quarto for interactive data exploration and reproducible documents.
10+
11+
- **[CLI](cli.qmd)** --- Execute queries and validate syntax from the command line.
12+
13+
- **[Python](python.qmd)** --- Use ggsql from Python.
14+
15+
- **[R](r.qmd)** --- Use ggsql from R.
16+
17+
- **[WebAssembly](webassembly.qmd)** --- Run ggsql entirely in the browser with no installation.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Jupyter & Quarto
3+
---
4+
5+
Once the ggsql Jupyter kernel has been installed you can use ggsql in Jupyter notebooks and Quarto documents.
6+
7+
## Installation
8+
9+
First, install ggsql on your system using the Jupyter kernel [installation instructions](../installation.html). If you do not already have Jupyter installed, you should install it in a new virtual environment using [uv](https://docs.astral.sh/uv/) or `pip` first:
10+
11+
```bash
12+
uv venv
13+
uv pip install jupyter
14+
uv pip install ggsql-jupyter
15+
source .venv/bin/activate
16+
ggsql-jupyter --install
17+
```
18+
19+
To verify installation, run `jupyter kernelspec list` and check that `ggsql` is listed as an available kernel.
20+
21+
```bash
22+
$ jupyter kernelspec list
23+
Available kernels:
24+
python3 /tmp/.venv/share/jupyter/kernels/python3
25+
ggsql /home/user/.local/share/jupyter/kernels/ggsql
26+
```
27+
28+
You can now use ggsql in your Quarto documents or Jupyter notebooks.
29+
30+
## Quarto documents
31+
32+
For a Quarto document, use the `ggsql` language name in a code block to tell the renderer to use the ggsql kernel:
33+
34+
````markdown
35+
```{{ggsql}}
36+
VISUALISE species AS fill
37+
FROM ggsql:penguins
38+
DRAW bar
39+
```
40+
````
41+
42+
Each block in the document shares the same session, so tables created in one block will be available in subsequent blocks.
43+
44+
![](./screenshots/quarto-document.png)
45+
46+
## Jupyter notebooks
47+
48+
First, start a Jupyter notebook server in your terminal:
49+
50+
```bash
51+
jupyter notebook
52+
```
53+
54+
When creating a new notebook, select the ggsql kernel from the kernel selector. Each cell in the notebook can contain a ggsql query, and the resulting visualisation will be displayed inline below the cell.
55+
56+
As with Quarto, each cell in the notebook uses the same session, so tables created in one cell will be available in subsequent cells.
57+
58+
![](./screenshots/jupyter-notebook.png)
59+
60+
## Database connections
61+
62+
By default, the ggsql kernel starts with an empty in-memory duckdb database connection. A "magic" comment can be used to initiate a different database connection after the session has launched, which can be either a comment in your Quarto code block or invoked directly in a Jupyter notebook cell.
63+
64+
The connection syntax is `-- @connect: [connection_uri]`, where `[connection_uri]` is a ggsql database connection string in the same format as accepted by the [ggsql CLI](cli.html).
65+
66+
![](./screenshots/jupyter-connections.png)

0 commit comments

Comments
 (0)