Skip to content

Commit f3f79e9

Browse files
committed
update documentation
1 parent a66538d commit f3f79e9

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- Fix a bug where the table component would not add the right css classes to table cells.
77
- Better error messages when a CSV import fails (using a `copy` statement and a file upload).
88
- Fix a bug where subsequent requests would fail after a failed CSV import on postgres (https://github.com/sqlpage/SQLPage/issues/788)
9+
- Complete rewrite of the request routing system.
10+
- Add support for *"clean URLs"*: Access the file `page.sql` using `https://example.com/page` instead of `https://example.com/page.sql`.
11+
- The previous behavior is preserved (the `.sql` suffix is now optional), so this is a new feature, not a breaking change.
12+
- Big thanks to @guspower who made big contributions to this feature.
913

1014
## 0.32.1 (2025-01-03)
1115

examples/official-site/index-old.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SELECT 'hero' as component,
99
'From database to data app, fast.' as title,
1010
'**SQLPage** lets you build data-driven applications in a few SQL queries.
1111
12-
Its free, [open-source](https://github.com/sqlpage/SQLPage), lightweight, and easy to use.
12+
It's free, [open-source](https://github.com/sqlpage/SQLPage), lightweight, and easy to use.
1313
' as description_md,
1414
'sqlpage_cover_image.webp' as image,
1515
TRUE as rounded,
@@ -93,12 +93,10 @@ write an `index.sql`, and in five minutes you turned your database into a websit
9393
We made all the [optimizations](performance.sql), wrote all of the HTTP request handling code and rendering logic,
9494
implemented all of the security features, so that you can think about your data, and nothing else.
9595

96-
When SQLPage receives a request with a URL ending in `.sql`, it finds the corresponding
97-
SQL file, runs it on the database, passing it information from the web request as SQL statement parameters
98-
[in a safe manner](safety.sql).
96+
When SQLPage receives a request, it finds the corresponding SQL file (with or without the .sql extension), runs it on the database, passing it information from the web request as SQL statement parameters [in a safe manner](safety.sql).
9997
When the database starts returning rows for the query,
10098
SQLPage maps each piece of information in the row to a parameter in the template of a pre-defined component,
101-
and streams the result back to the user''s browser.
99+
and streams the result back to the user's browser.
102100
' as description_md,
103101
'server' as icon,
104102
'purple' as color;

examples/official-site/sqlpage/migrations/47_link.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ VALUES
1616
1717
Let''s say you have a database of products, and you want the main page (`index.sql`) to link to the page of each product (`product.sql`) with the product name as a parameter.
1818
19-
In `index.sql`, you can use the `link` function to generate the URL of the product page for each product:
19+
In `index.sql`, you can use the `link` function to generate the URL of the product page for each product.
2020
2121
```sql
2222
select ''list'' as component;
2323
select
2424
name as title,
25-
sqlpage.link(''product.sql'', json_object(''product_name'', name)) as link;
25+
sqlpage.link(''product'', json_object(''product_name'', name)) as link;
2626
```
2727
28-
Using `sqlpage.link` is better than manually constructing the URL with `CONCAT(''product.sql?product_name='', name)`, because it ensures that the URL is properly encoded.
28+
Using `sqlpage.link` is better than manually constructing the URL with `CONCAT(''product?product_name='', name)`,
29+
because it ensures that the URL is properly encoded.
2930
The former works when the product name contains special characters like `&`, while the latter would break the URL.
3031
3132
In `product.sql`, you can then use `$product_name` to get the name of the product from the URL parameter:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ select 'text' as component, '
1313
1414
By default, SQLPage serves the file that matches the URL requested by the client.
1515
If your users enter `https://example.com/about`, SQLPage will serve the file `about/index.sql` in your project.
16-
If you create a file named `about.sql`, SQLPage will serve it when the user requests `https://example.com/about.sql`.
16+
If you create a file named `about.sql`, SQLPage will serve it when the user requests either `https://example.com/about.sql` or `https://example.com/about` (since v0.33, the `.sql` suffix is optional).
1717
1818
But what if you want to handle URLs that don''t match any file in your project ?
1919
For example, what if you have a blog, and you want nice urls like `example.com/blog/my-trip-to-rome`,

examples/official-site/your-first-sql-website/tutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can open your website locally by visiting [`http://localhost:8080`](http://l
1515

1616
SQLPage should have automatically created a folder called `sqlpage` with a SQLite database file named `sqlpage.db`. This is your website's default database - don't worry, we'll learn how to connect to other databases like PostgreSQL, MySQL, or SQL Server later!
1717

18-
# Your websites first SQL file
18+
# Your website's first SQL file
1919

2020
In the root folder of your SQLPage website, create a new SQL file called `index.sql`.
2121
Open it in a text editor that supports SQL syntax highlighting (I recommend [VSCode](https://code.visualstudio.com/)).
@@ -105,7 +105,7 @@ For more information about the properties that can be set in sqlpage.json, see [
105105

106106
### Displaying a form
107107

108-
Lets create a form to let our users insert data into our database. Add the following code to your `index.sql` file:
108+
Let's create a form to let our users insert data into our database. Add the following code to your `index.sql` file:
109109

110110
```sql
111111
SELECT 'form' AS component, 'Add a user' AS title;
@@ -117,7 +117,7 @@ The second SELECT statement adds a field to the form. Since we do not specify a
117117

118118
### Handling form submission
119119

120-
Nothing happens when you submit the form at the moment. Lets fix that.
120+
Nothing happens when you submit the form at the moment. Let's fix that.
121121
Add the following below the previous code:
122122

123123
```sql
@@ -136,7 +136,7 @@ from the text field when the user submits the form.
136136

137137
There are two types of parameters you can use in your SQL queries:
138138

139-
- **URL parameters** like **`$ParameterName`**. If you add `?x=1&y=2` to the end of the URL of your page, `$x` will be set to the string `'1'` and `$y` will be set to the string `'2'`. This is useful to create links with parameters. For instance, if you have a database of products, you can create a link to a product page with the URL `product.sql?product_id=12`. Then, in the `product.sql` file, you can use the `$product_id` variable to get the product with the corresponding ID from your database. URL parameters are also sometimes called *query parameters*, or *GET parameters*.
139+
- **URL parameters** like **`$ParameterName`**. If you add `?x=1&y=2` to the end of the URL of your page, `$x` will be set to the string `'1'` and `$y` will be set to the string `'2'`. This is useful to create links with parameters. For instance, if you have a database of products, you can create a link to a product page with the URL `product?product_id=12` (or `product.sql?product_id=12` - both work). Then, in the `product.sql` file, you can use the `$product_id` variable to get the product with the corresponding ID from your database. URL parameters are also sometimes called *query parameters*, or *GET parameters*.
140140
- **Form parameters** like **`:ParameterName`**. They refer to the value of the field with the corresponding `name` entered by the user in a [form](/component.sql?component=form). If no form was submitted, it is set to `NULL`. Form parameters are also sometimes called *POST parameters*.
141141

142142
> Note: Currently, if a `$parameter` is not present in the URL, it is first looked for in the form parameters. If it is not found there either, it is set to `NULL`. Please do not rely on this behavior, as it may change in the future.
@@ -152,8 +152,8 @@ INSERT INTO users (name) VALUES ($Username);
152152

153153
### Displaying data from our database
154154

155-
Now, users are present in our database, but we cant see them.
156-
Lets see how to use data from our database to populate a [list](/component.sql?component=list) component, in order to display the list of users.
155+
Now, users are present in our database, but we can't see them.
156+
Let's see how to use data from our database to populate a [list](/component.sql?component=list) component, in order to display the list of users.
157157

158158
Add the following code to your `index.sql` file:
159159

0 commit comments

Comments
 (0)