Skip to content

Commit 88ff0af

Browse files
committed
documentation
1 parent 7e4048c commit 88ff0af

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

examples/official-site/documentation.sql

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,35 @@ select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=
33
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
44

55
select 'text' as component, 'SQLPage documentation' as title;
6-
select 'Building an application with SQLPage is quite simple.' ||
7-
'To create a new web page, just create a new SQL file. ' ||
8-
'For each SELECT statement that you write, the data it returns will be analyzed and rendered to the user.';
9-
select 'The two most important concepts in SQLPage are ' as contents;
10-
select 'components' as contents, true as bold;
11-
select ' and ' as contents;
12-
select 'parameters' as contents, true as bold;
13-
select '. ' as contents;
14-
select 'This page documents all the components that you can use in SQLPage and their parameters. ' ||
15-
'Use this as a reference when building your SQL application.' as contents;
6+
select '
7+
Building an application with SQLPage is quite simple.
8+
To create a new web page, just create a new SQL file.
9+
For each SELECT statement that you write, the data it returns will be analyzed and rendered to the user.
10+
The two most important concepts in SQLPage are **components** and **parameters**.
11+
12+
- **components** are small user interface elements that you can use to display your data in a certain way.
13+
- *top-level* **parameters** are the properties of these components, allowing you to customize their appearance and behavior.
14+
- *row-level* **parameters** constitute the data that you want to display in the components.
15+
16+
To select a component and set its top-level properties, you write the following SQL statement:
17+
18+
```sql
19+
SELECT ''component_name'' AS component, ''my value'' AS top_level_parameter_1;
20+
```
21+
22+
Then, you can set its row-level parameters by writing a second SELECT statement:
23+
24+
```sql
25+
SELECT my_column_1 AS row_level_parameter_1, my_column_2 AS row_level_parameter_2 FROM my_table;
26+
```
27+
28+
This page documents all the components provided by default in SQLPage and their parameters.
29+
Use this as a reference when building your SQL application.
30+
31+
If you have some frontend development experience, you can also create your own components, by placing
32+
[`.handlebars`](https://handlebarsjs.com/guide/) files in a folder called `sqlpage/templates` at the root of your server.
33+
[See example](https://github.com/lovasoa/SQLpage/blob/main/sqlpage/templates/list.handlebars).
34+
' as contents_md;
1635

1736
select 'list' as component, 'components' as title;
1837
select
@@ -57,7 +76,7 @@ select
5776
{"component": "code"},
5877
{
5978
"title": "Example ' || (row_number() OVER ()) || '",
60-
"description": ' || json_quote(description) || ',
79+
"description_md": ' || json_quote(description) || ',
6180
"contents": ' || json_quote((
6281
select
6382
group_concat(

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,23 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
233233
INSERT INTO example(component, description, properties) VALUES
234234
(
235235
'form',
236-
'A form that asks the user for a parameter named "component", and then posts the results to another page named "documentation.sql".
237-
That file could contain a sql statement like "SELECT * FROM documentation WHERE component_name = $component" to display the documentation for the component the user selected.
238-
Or it could contain a sql statement like "INSERT INTO components(name) VALUES ($component)" to allow users to create a new component.',
236+
'
237+
A form that asks the user for a parameter named `component`, and then posts the results to another page named `documentation.sql`.
238+
That file could contain a sql statement like
239+
```sql
240+
SELECT * FROM documentation WHERE component_name = $component
241+
```
242+
to display the documentation for the component the user selected.
243+
244+
Or it could contain a sql statement like
245+
```sql
246+
INSERT INTO components(name) VALUES ($component)
247+
```
248+
249+
to allow users to create a new component.
250+
251+
When loading the page, the value for `$component` will be `NULL` if no value has been submitted.
252+
',
239253
json('[{"component":"form", "action": "documentation.sql"}, {"name": "component"}]')),
240254
('form', 'A user registration form.', json('[{"component":"form", "title": "User", "validate": "Create new user"}, '||
241255
'{"name": "First name", "placeholder": "John"}, '||

sqlpage/templates/code.handlebars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
{{#each_row}}
33
<h2>{{title}}</h2>
44
<p>{{description}}</p>
5+
{{#if description_md}}
6+
{{{markdown description_md}}}
7+
{{/if}}
58
<pre class="mb-0"><code>{{contents}}</code></pre>
69
{{/each_row}}
710
</div>

0 commit comments

Comments
 (0)