Skip to content

Commit 37a7303

Browse files
committed
Many improvements in the official website and the documentation.
Most notably, the documentation now has syntax highlighting on code blocks.
1 parent 9b873ca commit 37a7303

File tree

10 files changed

+94
-29
lines changed

10 files changed

+94
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## 0.14.0 (unreleased)
44

55
- Better error messages for Microsoft SQL Server. SQLPage now displays the line number of the error, which is especially useful for debugging long migration scripts.
6+
- Many improvements in the official website and the documentation.
7+
Most notably, the documentation now has syntax highlighting on code blocks.
68

79
## 0.13.0 (2023-10-16)
810
- New [timeline](https://sql.ophir.dev/documentation.sql?component=timeline#component) component to display a timeline of events.

examples/official-site/documentation.sql

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
-- This line, at the top of the page, tells web browsers to keep the page locally in cache once they have it.
22
select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control";
3-
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
3+
select
4+
'dynamic' as component,
5+
json_set(
6+
properties,
7+
'$[0].title',
8+
'SQLPage components' || COALESCE(': ' || $component, ' documentation')
9+
) as properties
10+
FROM example WHERE component = 'shell' LIMIT 1;
411

512
select 'text' as component, format('SQLPage v%s documentation', sqlpage.version()) as title;
613
select '
@@ -86,22 +93,31 @@ select
8693
{
8794
"title": "Example ' || (row_number() OVER ()) || '",
8895
"description_md": ' || json_quote(description) || ',
96+
"language": "sql",
8997
"contents": ' || json_quote((
9098
select
9199
group_concat(
92-
'SELECT ' || char(10) ||
100+
'select ' || char(10) ||
93101
(
102+
with t as (select * from json_tree(top.value))
94103
select group_concat(
95104
' ' ||
96-
CASE typeof(value)
97-
WHEN 'integer' THEN value::text
98-
WHEN 'real' THEN value::text
99-
ELSE quote(value::text)
105+
CASE t.type
106+
WHEN 'integer' THEN t.atom
107+
WHEN 'real' THEN t.atom
108+
WHEN 'true' THEN 'TRUE'
109+
WHEN 'false' THEN 'FALSE'
110+
WHEN 'null' THEN 'NULL'
111+
ELSE quote(t.value)
100112
END ||
101113
' as ' ||
102-
key
114+
CASE parent.fullkey
115+
WHEN '$' THEN t.key
116+
ELSE parent.key
117+
END
103118
, ',' || char(10)
104-
) from json_each(top.value)
119+
) from t inner join t parent on parent.id = t.parent
120+
where t.atom is not null
105121
) || ';',
106122
char(10)
107123
)

examples/official-site/functions.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
1+
select 'dynamic' as component,
2+
json_set(
3+
properties,
4+
'$[0].title',
5+
'SQLPage functions' || COALESCE(': ' || $function, ' documentation')
6+
) as properties
7+
FROM example WHERE component = 'shell' LIMIT 1;
28

39
select 'text' as component, 'SQLPage built-in functions' as title;
410
select '

examples/official-site/index.sql

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,36 @@ As an example, the list of features on this page is generated using a simple SQL
6060
6161
```sql
6262
SELECT ''card'' as component, ''What is SQLPage ?'' as title;
63-
SELECT header AS title, contents AS description FROM homepage_features;
63+
SELECT header AS title, contents AS description_md FROM homepage_features;
6464
```
6565
66-
Additionnally, SQLPage itself is written in a fast and secure programming language: Rust.
67-
We made all the optimizations so that you can think about your data, and nothing else.' as description_md,
66+
However, you can also create your own components, or edit the existing ones to customize your website to your liking.
67+
Creating a new component is as simple as creating an HTML template file.
68+
' as description_md,
6869
'rocket' as icon,
6970
'green' as color;
7071
SELECT 'Technically, it''s just a good old web server' as title,
7172
'
7273
The principles behind SQLPage are not too far from those that powered the early days of the internet.
73-
Like [PHP](https://en.wikipedia.org/wiki/PHP), SQLPage just receives a request, finds the file to execute, runs it, and returns a response.
74+
Like [PHP](https://en.wikipedia.org/wiki/PHP), SQLPage just receives a request, finds the file to execute, runs it,
75+
and returns a web page for the browser to display.
76+
77+
SQLPage is a *web server* written in a fast and secure programming language:
78+
[**Rust**](https://en.wikipedia.org/wiki/Rust_(programming_language)).
79+
It is extremely easy to use:
80+
you [download a single executable file](https://github.com/lovasoa/SQLpage/releases),
81+
write an `.sql` file, and you''re done.
82+
We made all the optimizations, wrote all of the HTTP request handling code and rendering logic,
83+
implemented all of the security features, so that you can think about your data, and nothing else.
7484
75-
SQLPage is a *web server* written in
76-
[rust](https://en.wikipedia.org/wiki/Rust_(programming_language))
77-
and [distributed as a single executable file](https://github.com/lovasoa/SQLpage/releases).
78-
When it receives a request with a URL ending in `.sql`, it finds the corresponding
85+
When SQLPage receives a request with a URL ending in `.sql`, it finds the corresponding
7986
SQL file, runs it on the database, passing it information from the web request as SQL statement parameters
8087
[in a safe manner](safety.sql).
8188
When the database starts returning rows for the query,
8289
SQLPage maps each piece of information in the row to a parameter in the template of a pre-defined component,
8390
and streams the result back to the user''s browser.
8491
' as description_md,
85-
'flask' as icon,
92+
'server' as icon,
8693
'purple' as color;
8794
SELECT 'Start Simple, Scale to Advanced' as title,
8895
'SQLPage is a great starting point for building websites, especially if you''re new to coding, or want to test out a new idea quickly.

examples/official-site/safety.sql

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ Most programmers, hearing this, will immediately think of the security implicati
1717
1818
This page is here to provide a list of the security guarantees that SQLPage provides.
1919
SQLPage was designed from the ground up to be usable by non-technical *data analysts* and other non-web-developers,
20-
so it provides safe defaults everywhere, so that you don''t have to worry about inadvertently
21-
exposing more data than you intended.
20+
so it provides safe defaults everywhere, so that you don''t have to think about basic security issues
21+
you would have to worry about in a traditional web development stack.
2222
23+
## SQLPage does not expose your database to the internet
24+
25+
SQLPage websites are *server-side rendered*, which means that the SQL queries stay on the server
26+
where SQLPage is installed.
27+
28+
The results of these queries are then rendered to HTML, and sent to the user''s browser.
29+
A malicious user cannot run arbitrary SQL queries on your database, because SQLPage does not expose your database to the internet.
2330
2431
## Protection against SQL injections
2532
@@ -76,6 +83,22 @@ that disallows the execution of any inline JavaScript code, and only allows load
7683
If you have some legitimate JavaScript code that you want to execute on your website, you can use the `javascript`
7784
parameter of the [`shell`](documentation.sql?component=shell#component) component to do so.
7885
86+
## Authentication
87+
88+
SQLPage provides an [authentication](/documentation.sql?component=authentication#component) component that allows you to
89+
restrict access to some pages of your website to authenticated users.
90+
91+
It also provides useful built-in functions such as
92+
[`sqlpage.basic_auth_username()`](/functions.sql?function=basic_auth_username#function),
93+
[`sqlpage.basic_auth_password()`](/functions.sql?function=basic_auth_password#function) and
94+
[`sqlpage.hash_password()`](/functions.sql?function=hash_password#function)
95+
to help you implement your authentication system entirely in SQL.
96+
97+
The components and functions provided by SQLPage are designed to be used by non-technical users,
98+
and to respect [security best practices](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) by default.
99+
Passwords are [hashed with a salt](https://en.wikipedia.org/wiki/Salt_(cryptography)) using the
100+
[argon2](https://en.wikipedia.org/wiki/Argon2) algorithm.
101+
79102
## Database connections
80103
81104
SQLPage uses a fixed pool of database connections, and will never open more connections than the ones you

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,19 @@ When loading the page, the value for `:username` will be `NULL` if no value has
286286
In this select input, the various options are hardcoded, but they could also be loaded from a database table,
287287
using a function to convert the rows into a json array like
288288
- `json_group_array()` in SQLite,
289-
- `json_agg()` in Postgres, or
290-
- `JSON_ARRAYAGG()` in MySQL.
289+
- `json_agg()` in Postgres,
290+
- `JSON_ARRAYAGG()` in MySQL, or
291291
- `FOR JSON PATH` in Microsoft SQL Server.
292292
293293
294294
In SQLite, the query would look like
295295
```sql
296296
SELECT
297297
''select'' as type,
298-
json_group_array(json_object("label", name, "value", id)) as options
298+
json_group_array(json_object(
299+
"label", name,
300+
"value", id
301+
)) as options
299302
FROM fruits
300303
```
301304
', json('[{"component":"form"}, '||
@@ -480,5 +483,8 @@ INSERT INTO example(component, description, properties) VALUES
480483
"description": "Documentation for the SQLPage low-code web application framework.",
481484
"font": "Poppins",
482485
"icon": "book",
486+
"javascript": ["https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-core.min.js",
487+
"https://cdn.jsdelivr.net/npm/prismjs@1/plugins/autoloader/prism-autoloader.min.js"],
488+
"css": "https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism-okaidia.min.css",
483489
"footer": "Official [SQLPage](https://sql.ophir.dev) documentation"
484490
}]'));

examples/official-site/sqlpage/migrations/07_authentication.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The username and password entered by the user will be accessible in your SQL cod
6262
6363
```sql
6464
SELECT ''authentication'' AS component,
65-
''$argon2id$v=19$m=16,t=2,p=1$TERTd0lIcUpraWFTcmRQYw$+bjtag7Xjb6p1dsuYOkngw'' AS password_hash, -- generated using https://argon2.online/
65+
''$argon2id$v=19$m=16,t=2,p=1$TERTd0lIcUpraWFTcmRQYw$+bjtag7Xjb6p1dsuYOkngw'' AS password_hash, -- generated using sqlpage.hash_password
6666
sqlpage.basic_auth_password() AS password; -- this is the password that the user entered in the browser popup
6767
```
6868
@@ -73,7 +73,7 @@ The most basic usage of the authentication component is to simply check if the u
7373
```sql
7474
SELECT ''authentication'' AS component,
7575
''login.sql'' AS link,
76-
''$argon2id$v=19$m=16,t=2,p=1$TERTd0lIcUpraWFTcmRQYw$+bjtag7Xjb6p1dsuYOkngw'' AS password_hash, -- generated using https://argon2.online/
76+
''$argon2id$v=19$m=16,t=2,p=1$TERTd0lIcUpraWFTcmRQYw$+bjtag7Xjb6p1dsuYOkngw'' AS password_hash, -- generated using sqlpage.hash_password
7777
:password AS password; -- this is the password that the user sent through our form
7878
```
7979

examples/official-site/sqlpage/migrations/17_blog_sqlpage_v_0_13.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ VALUES (
1515
- Updated dependencies, for bug fixes and performance improvements.
1616
- New icons (see https://tabler-icons.io/changelog)
1717
- When `NULL` is passed as an icon name, display no icon instead of raising an error.
18-
- Official docker image folder structure changed. The docker image now expects
18+
- The folder structure changed in the [official docker image](https://hub.docker.com/r/lovasoa/sqlpage). The docker image now expects
1919
- the SQLPage website (`.sql` files) to be in `/var/www/`, and
2020
- the SQLPage configuration folder to be in `/etc/sqlpage/`
2121
- the configuration file should be in `/etc/sqlpage/sqlpage.json`

examples/official-site/your-first-sql-website/index.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and render the database responses as nice web pages.
3636
3737
[Download the latest SQLPage](https://github.com/lovasoa/SQLpage/releases) for your operating system.
3838
39-
> **Note**: Advanced user can alternatively install SQLPage using
39+
> **Note**: Advanced users can alternatively install SQLPage using
4040
> [docker](https://hub.docker.com/repository/docker/lovasoa/sqlpage/general),
4141
> [brew](https://formulae.brew.sh/formula/sqlpage),
4242
> or [nix](https://search.nixos.org/packages?channel=unstable&show=sqlpage)
@@ -84,7 +84,7 @@ Your database schema
8484
====================
8585
8686
> If you already have a database populated with data,
87-
> or if you intend to use other tools to manage your database schema,
87+
> or if you intend to use other tools to manage your database structure,
8888
> you can skip this section.
8989
9090
The [database schema](https://en.wikipedia.org/wiki/Database_schema) for your SQLPage website
@@ -109,6 +109,9 @@ CREATE TABLE users (
109109
);
110110
```
111111
112+
> **Note**: The migration system is not supported on Microsoft SQL Server databases.
113+
> If you are using a SQL Server database, you should create your tables using a different tool, such as *SQL Server Management Studio*.
114+
112115
Connect to a custom database
113116
============================
114117

sqlpage/templates/code.handlebars

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{{#if description_md}}
66
{{{markdown description_md}}}
77
{{/if}}
8-
<pre class="mb-0"><code>{{contents}}</code></pre>
8+
<pre class="mb-0"><code
9+
{{#if language}}class="language-{{language}}"{{/if}}
10+
>{{contents}}</code></pre>
911
{{/each_row}}
1012
</div>

0 commit comments

Comments
 (0)