docs: adding documentation for markdown tables

This commit is contained in:
Kacper Kula 2025-01-16 14:11:44 +00:00
parent d7b719db7b
commit 3f0691058a
2 changed files with 53 additions and 0 deletions

View file

@ -21,6 +21,7 @@ export default defineConfig({
{ text: 'Changing Render Methods', link: '/changing-render-method'},
{ text: 'Using properties', link: '/using-properties' },
{ text: 'Query Vault Content', link: '/query-vault-content' },
{ text: 'Query Markdown Tables', link: '/query-markdown-tables'},
{ text: 'Inline codeblocks', link: '/inline-codeblocks' },
{ text: 'Links and Images', link: '/links-and-images' },
{ text: 'CSV Viewer', link: '/csv-viewer'},

View file

@ -0,0 +1,52 @@
# Querying Markdown Tables
> [!NOTE] Compatibility
> Introduced in version 0.16.0. Make sure you are using up to date version.
You can refer to the tables in your current file by using `table(tableIndex)` syntax. This can allow you to quickly summarise data you might have in your document.
Indexing starts from 0 so the 1st table should be refered to as `table(0)`, 2nd table `table(1)` and so on.
## Example
Let's take a note with the following table:
| Date | Name | Amount |
| ---------- | ------------- | ------ |
| 2025-01-01 | Grocery | 20.40 |
| 2025-01-01 | Cinema Ticket | 8.20 |
| 2025-01-02 | Grocery | 5.0 |
| 2025-01-02 | Game on Steam | 20.0 |
| 2025-01-03 | Grocery | 15.98 |
We can refer to this data and summarise spendings each day by doing the following:
```sqlseal
TABLE expenses = table(0)
HTML
SELECT date, ROUND(SUM(Amount), 2) as Spent
FROM expenses
GROUP BY date
ORDER BY date
```
Result:
| date | Spent |
| ---------- | ----- |
| 2025-01-01 | 28.6 |
| 2025-01-02 | 25 |
| 2025-01-03 | 15.98 |
## Inline query
You can also use this data to perform inline query, i.e. you can make sentence reading "I've spent in total X" and make X being a query. The only limitation here is that you need to have another query in the file that defines the table for the markdown table (because inline queries do not allow for defining new tables).
```sqlseal
TABLE expenses = table(0)
```
And then anywhere else in your code:
I've spent total of `S> SELECT ROUND(SUM(amount), 2) FROM expenses`.
Result:
I've spent in total `69.58`.