Skip to content

Commit 90f49ce

Browse files
committed
Notebooks doc
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
1 parent 986b099 commit 90f49ce

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

src/content/docs/extensions/db2i/index.mdx

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,97 @@ We have added Visual Explain into the database extension with a more lightweight
8484

8585
The Visual Explain view has button on the header to control which nodes should be highlights, as well as the ability to export the data as JSON, and more.
8686

87-
![](./dove.png)
87+
![](./dove.png)
88+
89+
## Notebooks
90+
91+
Notebooks now supports Db2 for IBM i when using the database extension. If you have not heard of Notebooks before, [check out this blog post](https://code.visualstudio.com/blogs/2021/11/08/custom-notebooks) on the Visual Studio Blog. IBM i Notebooks allow users to build documents of markdown, SQL statements and CL commands all in one view, that can be saved, re-used, re-run and shared to other people. This allows you to create documentation, a step-by-step guide, and many other things, specifically for IBM i.
92+
93+
![](./notebook.png)
94+
95+
<Aside type="tip">
96+
We are expecting a full release of Notebooks in vscode-db2i 1.0.0.
97+
</Aside>
98+
99+
### How to create a Notebook
100+
101+
There are a few ways to create an IBM i Notebook:
102+
103+
1. You can use the 'New Notebook' button on the SQL Job Manager
104+
2. You can find 'IBMi i: New Notebook' in the command palette.
105+
3. Open a `.inb` file (which stands for 'i Notebook')
106+
107+
### The life of a Notebook
108+
109+
A notebook is made up of cells. A cell is asscociated with a language (for example, `sql`, `cl`, or `markdown`). Cells (other than `markdown`) can be executed. Each cell has a result and typically gets rendered below the cell input after execution.
110+
111+
Execution is different for each language type:
112+
113+
* If it is `sql`, then a table will be returned of the result set. Notebooks do not support paging - it will return all rows. The SQL statements will be executed through the selected job in the SQL Job Manager.
114+
* If the language is `cl`, then when it is executed it will run a CL command and return the resulting output.
115+
116+
You are able to use the stop and play buttons on the cells to request a cancellation of the execution.
117+
118+
### Charting with SQL
119+
120+
Notebooks have the power to chart data that is returned from the database. It is most useful for rendering numerical data (on the Y axis) by another value (on the X axix). Here are the supported chart types, which are used for specifying the chart type:
121+
122+
* bar
123+
* line
124+
* doughnut
125+
* pie
126+
* polar area (`polarArea`)
127+
* radar
128+
129+
To render a chart using SQL in a Notebook, two rules must be met:
130+
131+
1. You must provide the chart type (via comment tag or statement prefix)
132+
2. There must be a `LABEL` column for the X axis.
133+
3. One or more numeric columns for the plotted data
134+
* You can also provide a `_description` string column for each numeric column to provide additional information in the tooltip
135+
* For numeric columns to use formatted names, provide a fixed column name: `salary as "Salary"`
136+
137+
Optional tags as comments can also be provided. Optional tags are formatted as so:
138+
139+
* `chart` - which can be used instead of the chart prefix
140+
* `title` - appears above the chart for a title
141+
* `y` - for a title to appear on the Y axis
142+
143+
<Tabs>
144+
<TabItem label="Tags">
145+
146+
```sql
147+
--chart: bar
148+
select
149+
empno as label,
150+
salary
151+
from sample.employee limit 10
152+
```
153+
154+
</TabItem>
155+
<TabItem label="Tooltip">
156+
157+
```sql
158+
--chart: bar
159+
--y: NZD
160+
select empno as label,
161+
salary as "Salary", 'Does not include ' concat rtrim(char(bonus)) concat '\nbonus for ' concat rtrim(firstnme) as "Salary_desc"
162+
from sample.employee limit 10
163+
```
164+
165+
</TabItem>
166+
<TabItem label="Multiple Datapoints">
167+
168+
```sql
169+
--title:
170+
--chart: line
171+
select
172+
empno as label,
173+
salary, bonus
174+
from sample.employee
175+
order by salary asc
176+
limit 10
177+
```
178+
179+
</TabItem>
180+
</Tabs>
864 KB
Loading

0 commit comments

Comments
 (0)