Skip to content

Commit 1fec208

Browse files
committed
Update 47_link.sql
1 parent 963ec10 commit 1fec208

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ select
2626
from products;
2727
```
2828
29-
Using `sqlpage.link` is better than manually constructing the URL with `CONCAT(''product?product_name='', name)`,
30-
because it ensures that the URL is properly encoded.
31-
The former works when the product name contains special characters like `&`, while the latter would break the URL.
32-
3329
In `product.sql`, you can then use `$product_name` to get the name of the product from the URL parameter:
3430
3531
```sql
36-
select ''text'' as component;
37-
select CONCAT(''Product: '', $product_name) as contents;
32+
select ''hero'' as component, $product_name as title, product_info as description
33+
from products
34+
where name = $product_name;
3835
```
3936
37+
> You could also have manually constructed the URL with `CONCAT(''product?product_name='', name)`,
38+
> but using `sqlpage.link` is better because it ensures that the URL is properly encoded.
39+
> `sqlpage.link` will work even if the product name contains special characters like `&`, while `CONCAT(...)` would break the URL.
40+
4041
### Parameters
4142
- `file` (TEXT): The name of the SQLPage file to link to.
4243
- `parameters` (JSON): The parameters to pass to the linked file.

0 commit comments

Comments
 (0)