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
Copy file name to clipboardExpand all lines: examples/official-site/index-old.sql
+3-5Lines changed: 3 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ SELECT 'hero' as component,
9
9
'From database to data app, fast.'as title,
10
10
'**SQLPage** lets you build data-driven applications in a few SQL queries.
11
11
12
-
It’s 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.
13
13
' as description_md,
14
14
'sqlpage_cover_image.webp' as image,
15
15
TRUE as rounded,
@@ -93,12 +93,10 @@ write an `index.sql`, and in five minutes you turned your database into a websit
93
93
We made all the [optimizations](performance.sql), wrote all of the HTTP request handling code and rendering logic,
94
94
implemented all of the security features, so that you can think about your data, and nothing else.
95
95
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).
99
97
When the database starts returning rows for the query,
100
98
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.
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/47_link.sql
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,16 +16,17 @@ VALUES
16
16
17
17
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.
18
18
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.
20
20
21
21
```sql
22
22
select ''list'' as component;
23
23
select
24
24
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;
26
26
```
27
27
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.
29
30
The former works when the product name contains special characters like `&`, while the latter would break the URL.
30
31
31
32
In `product.sql`, you can then use `$product_name` to get the name of the product from the URL parameter:
Copy file name to clipboardExpand all lines: examples/official-site/your-first-sql-website/custom_urls.sql
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ select 'text' as component, '
13
13
14
14
By default, SQLPage serves the file that matches the URL requested by the client.
15
15
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).
17
17
18
18
But what if you want to handle URLs that don''t match any file in your project ?
19
19
For example, what if you have a blog, and you want nice urls like `example.com/blog/my-trip-to-rome`,
Copy file name to clipboardExpand all lines: examples/official-site/your-first-sql-website/tutorial.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ You can open your website locally by visiting [`http://localhost:8080`](http://l
15
15
16
16
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!
17
17
18
-
# Your website’s first SQL file
18
+
# Your website's first SQL file
19
19
20
20
In the root folder of your SQLPage website, create a new SQL file called `index.sql`.
21
21
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 [
105
105
106
106
### Displaying a form
107
107
108
-
Let’s 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:
109
109
110
110
```sql
111
111
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
117
117
118
118
### Handling form submission
119
119
120
-
Nothing happens when you submit the form at the moment. Let’s fix that.
120
+
Nothing happens when you submit the form at the moment. Let's fix that.
121
121
Add the following below the previous code:
122
122
123
123
```sql
@@ -136,7 +136,7 @@ from the text field when the user submits the form.
136
136
137
137
There are two types of parameters you can use in your SQL queries:
138
138
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*.
140
140
-**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*.
141
141
142
142
> 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);
152
152
153
153
### Displaying data from our database
154
154
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.
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.
0 commit comments