From 3f0691058a83d91471fa57cfa05cb9e14e0f815e Mon Sep 17 00:00:00 2001 From: Kacper Kula Date: Thu, 16 Jan 2025 14:11:44 +0000 Subject: [PATCH] docs: adding documentation for markdown tables --- docs/.vitepress/config.mts | 1 + docs/query-markdown-tables.md | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 docs/query-markdown-tables.md diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 4554575..84b7c40 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -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'}, diff --git a/docs/query-markdown-tables.md b/docs/query-markdown-tables.md new file mode 100644 index 0000000..cf1604b --- /dev/null +++ b/docs/query-markdown-tables.md @@ -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`. \ No newline at end of file