Files
sqlpage--sqlpage/examples/official-site/examples/dynamic_shell.sql
T
wehub-resource-sync d718c5a372
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:57 +08:00

129 lines
3.8 KiB
SQL

SELECT 'dynamic' AS component, json_object(
'component', 'shell',
'title', 'SQLPage documentation',
'link', '/',
'menu_item', json_array(
json_object(
'link', '/',
'title', 'Home'
),
json_object(
'title', 'Community',
'submenu', json_array(
json_object(
'link', '/blog.sql',
'title', 'Blog'
),
json_object(
'link', 'https://github.com/sqlpage/SQLPage/issues',
'title', 'Issues'
),
json_object(
'link', 'https://github.com/sqlpage/SQLPage/discussions',
'title', 'Discussions'
),
json_object(
'link', 'https://github.com/sqlpage/SQLPage',
'title', 'Github'
)
)
)
),
'javascript', json_array(
'https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-core.min.js',
'https://cdn.jsdelivr.net/npm/prismjs@1/plugins/autoloader/prism-autoloader.min.js'
),
'css', '/prism-tabler-theme.css'
) AS properties;
select 'text' as component,
'## Dynamic properties
The menu of this page is generated using the `dynamic` component with the following SQL query:
```sql
SELECT ''dynamic'' AS component, json_object(
''component'', ''shell'',
''title'', ''SQLPage documentation'',
''link'', ''/'',
''menu_item'', json_array(
json_object(
''link'', ''/'',
''title'', ''Home''
),
json_object(
''title'', ''Community'',
''submenu'', json_array(
json_object(
''link'', ''/blog.sql'',
''title'', ''Blog''
),
json_object(
''link'', ''https://github.com/sqlpage/SQLPage/issues'',
''title'', ''Issues''
),
json_object(
''link'', ''https://github.com/sqlpage/SQLPage/discussions'',
''title'', ''Discussions''
),
json_object(
''link'', ''https://github.com/sqlpage/SQLPage'',
''title'', ''Github''
)
)
)
)
) AS properties
```
## Dynamic properties from the database
One could also store the menu items in the database,
using a structure like this:
```sql
CREATE TABLE menu_items (
id INTEGER PRIMARY KEY,
title TEXT,
link TEXT,
parent_id INTEGER REFERENCES menu_items(id)
);
INSERT INTO menu_items (id, title, link, parent_id) VALUES
(1, ''Home'', ''/'', NULL),
(2, ''Community'', NULL, NULL),
(3, ''Blog'', ''blog.sql'', 2),
(4, ''Issues'', ''https://github.com/sqlpage/SQLPage/issues'', 2),
(5, ''Discussions'', ''https://github.com/sqlpage/SQLPage/discussions'', 2),
(6, ''Github'', ''https://github.com/sqlpage/SQLPage'', 2);
```
Then, one could use the following SQL query to fetch
and generate the menu from the database:
```sql
SELECT ''dynamic'' AS component, json_object(
''component'', ''shell'',
''title'', ''SQLPage documentation'',
''link'', ''/'',
''menu_item'', json_group_array(
json_object(
''link'', link,
''title'', title,
''submenu'', (
select json_group_array(
json_object(
''link'', submenu.link,
''title'', submenu.title
)
) FROM menu_items AS submenu
WHERE menu_items.id = submenu.parent_id
HAVING COUNT(*) > 0
)
)
)
) AS properties
FROM menu_items
WHERE parent_id IS NULL
```
' as contents_md;