sqlpage.link(file, parameters, fragment)
Introduced in SQLPage 0.25.0.
Returns the URL of a SQLPage file with the given parameters.
Example
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.
In index.sql
, you can use the link
function to generate the URL of the product page for each product:
select 'list' as component;
select
name as title,
sqlpage.link('product.sql', json_object('product_name', name)) as link;
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.
The former works when the product name contains special characters like &
, while the latter would break the URL.
In product.sql
, you can then use $product_name
to get the name of the product from the URL parameter:
select 'text' as component;
select CONCAT('Product: ', $product_name) as contents;
Parameters
file
(TEXT): The name of the SQLPage file to link to.parameters
(JSON): The parameters to pass to the linked file.fragment
(TEXT): An optional fragment (hash) to append to the URL. This is useful for linking to a specific section of a page. For instance ifproduct.sql
containsselect 'text' as component, 'product_description' as id;
, you can link to the product description section withsqlpage.link('product.sql', json_object('product_name', name), 'product_description')
.
Parameters
file
The path of the SQLPage file to link to, relative to the current file.
parameters
A JSON object with the parameters to pass to the linked file.
fragment
An optional fragment (hash) to append to the URL to link to a specific section of the target page.
basic_auth_password
basic_auth_username
cookie
current_working_directory
environment_variable
exec
fetch
hash_password
header
link
path
persist_uploaded_file
protocol
random_string
read_file_as_data_url
read_file_as_text
request_method
run_sql
uploaded_file_mime_type
uploaded_file_name
uploaded_file_path
url_encode
variables
version