You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`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.
22
25
|`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. |
23
26
|`https_acme_directory_url`|https://acme-v02.api.letsencrypt.org/directory| The URL of the ACME directory to use when requesting a certificate. |
24
27
25
-
You can find an example configuration file in [`sqlpage/sqlpage.json`](./sqlpage/sqlpage.json).
26
-
27
28
Multiple configuration file formats are supported:
28
29
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.
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.
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
+
- 
0 commit comments