Skip to content

Commit ee41316

Browse files
committed
v0.17 release notes
1 parent edaea83 commit ee41316

File tree

4 files changed

+180
-5
lines changed

4 files changed

+180
-5
lines changed

configuration.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
SQLPage can be configured through either [environment variables](https://en.wikipedia.org/wiki/Environment_variable)
44
on a [JSON](https://en.wikipedia.org/wiki/JSON) file placed in `sqlpage/sqlpage.json`.
55

6+
You can find an example configuration file in [`sqlpage/sqlpage.json`](./sqlpage/sqlpage.json).
7+
Here are the available configuration options and their default values:
8+
69
| variable | default | description |
710
| ------------------------------------------ | ---------------------------- | ------------------------------------------------------------------------ |
811
| `listen_on` | 0.0.0.0:8080 | Interface and port on which the web server should listen |
@@ -22,8 +25,6 @@ on a [JSON](https://en.wikipedia.org/wiki/JSON) file placed in `sqlpage/sqlpage.
2225
| `https_certificate_cache_dir` | ./sqlpage/https | A writeable directory where to cache the certificates, so that SQLPage can serve https traffic immediately when it restarts. |
2326
| `https_acme_directory_url` | https://acme-v02.api.letsencrypt.org/directory | The URL of the ACME directory to use when requesting a certificate. |
2427

25-
You can find an example configuration file in [`sqlpage/sqlpage.json`](./sqlpage/sqlpage.json).
26-
2728
Multiple configuration file formats are supported:
2829
you can use a [`.json5`](https://json5.org/) file, a [`.toml`](https://toml.io/) file, or a [`.yaml`](https://en.wikipedia.org/wiki/YAML#Syntax) file.
2930

examples/official-site/blog.sql

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ select 'shell' as component,
77
'blog' as menu_item,
88
'documentation' as menu_item,
99
19 as font_size,
10-
'Poppins' as font;
11-
10+
'Poppins' as font,
11+
'https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-core.min.js' as javascript,
12+
'https://cdn.jsdelivr.net/npm/prismjs@1/plugins/autoloader/prism-autoloader.min.js' as javascript,
13+
'/prism-tabler-theme.css' as css;
14+
1215
SELECT 'text' AS component,
1316
content AS contents_md
1417
FROM blog_posts

examples/official-site/sqlpage/migrations/24_read_file_as_data_url.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ select ''card'' as component;
4242
select ''Picture'' as title, sqlpage.read_file_as_data_url(''/path/to/picture.jpg'') as top_image;
4343
```
4444
45-
> **Note:** Data URLs are larger than the original file they represent, so they should only be used for small files (a few kilobytes).
45+
> **Note:** Data URLs are larger than the original file they represent, so they should only be used for small files
46+
> (under a few hundred kilobytes).
4647
> Otherwise, the page will take a long time to load.
4748
');
4849

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
INSERT INTO blog_posts (title, description, icon, created_at, content)
2+
VALUES (
3+
'SQLPage v0.17',
4+
'SQLPage v0.17 introduces file uploads, HTTPS, and more.',
5+
'git-fork',
6+
'2023-11-28',
7+
'
8+
# SQLPage v0.17 is out !
9+
10+
[SQLPage](/) is a web application server that lets you build entire web applications with just SQL queries.
11+
v0.17 was just released, and it''s worth a blog post to highlight some of the coolest new features.
12+
13+
Mostly, this release makes it a matter of minutes to build a data import pipeline for your website,
14+
and a matter of seconds to deploy your SQLPage website securely with automatic HTTPS certificates.
15+
16+
## Uploads
17+
18+
This release is all about a long awaited feature: **file uploads**.
19+
Your SQLPage website can now accept file uploads from users,
20+
store them either in a directory or directly in a database table.
21+
22+
You can add a file upload button to a form with a simple
23+
24+
```sql
25+
select ''form'' as component;
26+
select ''profile_picture'' as name, ''file'' as type;
27+
```
28+
29+
when received by the server, the file will be saved in a temporary directory
30+
(customizable with `TMPDIR` on linux).
31+
You can access the temporary file path with
32+
the new [`sqlpage.uploaded_file_path`](/functions.sql?function=uploaded_file_path#function) function.
33+
34+
You can then persist the upload as a permanent file on the server with the
35+
[`sqlpage.exec`](https://sql.ophir.dev/functions.sql?function=exec#function) function:
36+
37+
```sql
38+
set file_path = sqlpage.uploaded_file_path(''profile_picture'');
39+
select sqlpage.exec(''mv'', $file_path, ''/path/to/my/file'');
40+
```
41+
42+
or you can store it directly in a database table with the new
43+
[`sqlpage.read_file_as_data_url`](https://sql.ophir.dev/functions.sql?function=read_file_as_data_url#function) and
44+
[`sqlpage.read_file_as_text`](https://sql.ophir.dev/functions.sql?function=read_file_as_text#function) functions:
45+
46+
```sql
47+
insert into files (url) values (sqlpage.read_file_as_data_url(sqlpage.uploaded_file_path(''profile_picture'')))
48+
returning ''text'' as component, ''Uploaded new file with id: '' || id as contents;
49+
```
50+
51+
The maximum size of uploaded files is configurable with the [`max_uploaded_file_size`](https://github.com/lovasoa/SQLpage/blob/main/configuration.md)
52+
configuration parameter. By default, it is set to 5 MiB.
53+
54+
### Parsing CSV files
55+
56+
SQLPage can also parse uploaded [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) files and insert them directly into a database table.
57+
SQLPage re-uses PostgreSQL''s [`COPY` syntax](https://www.postgresql.org/docs/current/sql-copy.html)
58+
to import the CSV file into the database.
59+
When connected to a PostgreSQL database, SQLPage will use the native `COPY` statement,
60+
for super fast and efficient on-database CSV parsing.
61+
But it will also work with any other database as well, by
62+
parsing the CSV locally and emulating the same behavior with simple `INSERT` statements.
63+
64+
#### `user_file_upload.sql`
65+
```sql
66+
select ''form'' as component, ''bulk_user_import.sql'' as action;
67+
select ''user_csv_file'' as name, ''file'' as type, ''text/csv'' as accept;
68+
```
69+
70+
#### `bulk_user_import.sql`
71+
```sql
72+
-- create a temporary table to preprocess the data
73+
create temporary table if not exists csv_import(name text, age text);
74+
delete from csv_import; -- empty the table
75+
-- If you don''t have any preprocessing to do, you can skip the temporary table and use the target table directly
76+
77+
copy csv_import(name, age) from ''user_csv_file''
78+
with (header true, delimiter '','', quote ''"'', null ''NaN''); -- all the options are optional
79+
-- since header is true, the first line of the file will be used to find the "name" and "age" columns
80+
-- if you don''t have a header line, the first column in the CSV will be interpreted as the first column of the table, etc
81+
82+
-- run any preprocessing you want on the data here
83+
84+
-- insert the data into the users table
85+
insert into users (name, birth_date)
86+
select upper(name), date_part(''year'', CURRENT_DATE) - cast(age as int) from csv_import;
87+
```
88+
89+
### New functions
90+
91+
#### Handle uploaded files
92+
93+
- [`sqlpage.uploaded_file_path`](https://sql.ophir.dev/functions.sql?function=uploaded_file_path#function) to get the temprary local path of a file uploaded by the user. This path will be valid until the end of the current request, and will be located in a temporary directory (customizable with `TMPDIR`). You can use [`sqlpage.exec`](https://sql.ophir.dev/functions.sql?function=exec#function) to operate on the file, for instance to move it to a permanent location.
94+
- [`sqlpage.uploaded_file_mime_type`](https://sql.ophir.dev/functions.sql?function=uploaded_file_mime_type#function) to get the type of file uploaded by the user. This is the MIME type of the file, such as `image/png` or `text/csv`. You can use this to easily check that the file is of the expected type before storing it.
95+
96+
The new [*Image gallery* example](https://github.com/lovasoa/SQLpage/tree/main/examples/image%20gallery%20with%20user%20uploads)
97+
in the official repository shows how to use these functions to create a simple image gallery with user uploads.
98+
99+
#### Read files
100+
101+
These new functions are useful to read the contents of a file uploaded by the user,
102+
but can also be used to read any file on the computer where SQLPage is running:
103+
104+
- [`sqlpage.read_file_as_text`](https://sql.ophir.dev/functions.sql?function=read_file_as_text#function) reads the contents of a file on the server and returns a text string.
105+
- [`sqlpage.read_file_as_data_url`](https://sql.ophir.dev/functions.sql?function=read_file_as_data_url#function) reads the contents of a file on the server and returns a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). This is useful to embed images directly in web pages, or make link
106+
107+
## HTTPS
108+
109+
This is the other big feature of this release: SQLPage now supports HTTPS !
110+
Until now, if you wanted to use HTTPS with SQLPage, you had to put it behind a
111+
*reverse proxy*, which is what the official documentation website does.
112+
113+
This required a lot of manual configuration
114+
that would compromise your security if you get it wrong.
115+
116+
With SQLPage v0.17, you just give your domain name,
117+
and it takes care of everything.
118+
119+
And while we''re at it, SQLPage also supports HTTP/2, for even faster page loads.
120+
121+
To enable HTTPS, you need to buy a [domain name](https://en.wikipedia.org/wiki/Domain_name)
122+
and make it point to the server where SQLPage is running.
123+
Then set the `https_domain` configuration parameter to `yourdomain.com` in your [`sqlpage.json` configuration file](./configuration.md).
124+
125+
```json
126+
{
127+
"https_domain": "my-cool-website.com"
128+
}
129+
```
130+
131+
That''s it. No external tool to install, no certificate to generate, no configuration to tweak.
132+
No need to restart SQLPage regularly either, or to worry about renewing your certificate when it expires.
133+
SQLPage will automatically request a certificate from [Let''s Encrypt](https://letsencrypt.org/) by default,
134+
and does not even need to listen on port 80 to do so.
135+
136+
## SQL parser improvements
137+
138+
SQLPage needs to parse SQL queries to be able to bind the right parameters to them,
139+
and to inject the results of built-in sqlpage functions in them.
140+
The parser we use is very powerful and supports most SQL features,
141+
but there are some edge cases where it fails to parse a query.
142+
That''s why we contribute to it a lot, and bring the latest version of the parser to SQLPage as soon as it is released.
143+
144+
### JSON functions in MS SQL Server
145+
146+
SQLPage now supports the [`FOR JSON` syntax](https://learn.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server?view=sql-server-ver16&tabs=json-path) in MS SQL Server.
147+
148+
This unlocks a lot of new possibilities, that were previously only available in other databases.
149+
150+
This is particularly interesting to build complex menus with the `shell` component,
151+
to build multiple-answer select inputs with the `form` component,
152+
and to create JSON APIs.
153+
154+
### Other sql syntax enhancements
155+
156+
- SQLPage now supports the custom `CONVERT` expression syntax for MS SQL Server, and the one for MySQL.
157+
- The `VARCHAR(MAX)` type in MS SQL Server new works. We now use it for all variables bound as parameters to your SQL queries (we used to use `VARCHAR(8000)` before).
158+
- `INSERT INTO ... DEFAULT VALUES ...` is now parsed correctly.
159+
160+
## Other news
161+
162+
- Dates and timestamps returned from the database are now always formatted in ISO 8601 format, which is the standard format for dates in JSON. This makes it easier to use dates in SQLPage.
163+
- The `cookie` component now supports setting an explicit expiration date for cookies.
164+
- The `cookie` component now supports setting the `SameSite` attribute of cookies, and defaults to `SameSite=Strict` for all cookies. What this means in practice is that cookies set by SQLPage will not be sent to your website if the user is coming from another website. This prevents someone from tricking your users into executing SQLPage queries on your website by sending them a malicious link.
165+
- Bugfix: setting `min` or `max` to `0` in a number field in the `form` component now works as expected.
166+
- Added support for `.env` files to set SQLPage''s [environment variables](./configuration.md#environment-variables).
167+
- Better responsive design in the card component. Up to 5 cards per line on large screens. The number of cards per line is still customizable with the `columns` attribute.
168+
- [New icons](https://tabler-icons.io/changelog):
169+
- ![new icons in tabler 42](https://github.com/tabler/tabler-icons/assets/1282324/00856af9-841d-4aa9-995d-121c7ddcc005)
170+
');

0 commit comments

Comments
 (0)