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
{{ message }}
Repository navigation
Commit 3bc22e2
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: examples/official-site/content/blog/file-based-routing-in-sqlpage.md
+11-15Lines changed: 11 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
+
---
2
+
title: File-based routing in SQLPage
3
+
date: '2025-07-28'
4
+
icon: route
5
+
summary: Understanding how SQLPage maps URLs to files and handles errors
6
+
---
1
7
2
-
INSERT INTO blog_posts (title, description, icon, created_at, content)
3
-
VALUES
4
-
(
5
-
'File-based routing in SQLPage',
6
-
'Understanding how SQLPage maps URLs to files and handles errors',
7
-
'route',
8
-
'2025-07-28',
9
-
'
10
8
SQLPage uses a simple file-based routing system that maps URLs directly to SQL files in your project directory.
11
9
No complex configuration is needed. Just create files and they become accessible endpoints.
12
10
@@ -16,7 +14,7 @@ This guide explains how SQLPage resolves URLs, handles different file types, and
16
14
17
15
### 1. Site Prefix Handling
18
16
19
-
If you''ve configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
17
+
If you've configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
20
18
SQLPage will redirect all requests that do not start with the prefix to `/<site_prefix>`.
21
19
22
20
### 2. Path Resolution Priority
@@ -27,18 +25,18 @@ SQLPage will redirect all requests that do not start with the prefix to `/<site_
27
25
28
26
**Static asset requests (other extensions)**: SQLPage serves files like CSS, JavaScript, images, or any other static content directly.
29
27
30
-
**Clean URL requests (no extension)**: SQLPage first tries to find a matching `.sql` file. If that doesn''t exist but there''s an `index.sql` file in a directory with the same name, it redirects to the directory path with a trailing slash.
28
+
**Clean URL requests (no extension)**: SQLPage first tries to find a matching `.sql` file. If that doesn't exist but there's an `index.sql` file in a directory with the same name, it redirects to the directory path with a trailing slash.
31
29
32
30
Paths with trailing spaces are rejected. On Windows, paths with trailing dots or NTFS stream names are rejected too. These spellings can refer to a different file than their URL suggests on some storage systems.
33
31
34
32
### Error Handling
35
33
36
-
When, after applying each of the rules above in order, SQLPage can''t find a requested file,
34
+
When, after applying each of the rules above in order, SQLPage can't find a requested file,
37
35
it walks up your directory structure looking for [custom `404.sql` files](/your-first-sql-website/custom_urls).
38
36
39
37
## Dynamic Routing with SQLPage
40
38
41
-
SQLPage''s file-based routing becomes powerful when combined with strategic use of 404.sql files to handle dynamic URLs. Here''s how to build APIs and pages with dynamic parameters:
39
+
SQLPage's file-based routing becomes powerful when combined with strategic use of 404.sql files to handle dynamic URLs. Here's how to build APIs and pages with dynamic parameters:
42
40
43
41
### Product Catalog with Dynamic IDs
44
42
@@ -59,7 +57,5 @@ products/
59
57
60
58
**In `products/404.sql`**:
61
59
```sql
62
-
set product_id = substr(sqlpage.path(), 1+length(''/products/''));
60
+
set product_id = substr(sqlpage.path(), 1+length('/products/'));
Copy file name to clipboardExpand all lines: examples/official-site/content/blog/how-i-built-a-360-performance-monitoring-tool-with-sql-queries.md
+31-34Lines changed: 31 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
+
---
2
+
title: How I built a 360° performance monitoring tool with SQL Queries
3
+
date: '2025-01-25'
4
+
icon: shirt
5
+
summary: Alexis built a performance monitoring tool with SQLPage for a 100M€/year company
6
+
---
1
7
2
-
INSERT INTO blog_posts (title, description, icon, created_at, content)
3
-
VALUES
4
-
(
5
-
'How I built a 360° performance monitoring tool with SQL Queries',
6
-
'Alexis built a performance monitoring tool with SQLPage for a 100M€/year company',
7
-
'shirt',
8
-
'2025-01-25',
9
-
'
10
8
# How I Built And Deployed An Exhaustive Performance Monitoring Tool For a 100M€/year Company Using SQL Queries Only
11
9
12
10
### Building web applications in SQL
@@ -48,12 +46,12 @@ I am using SQLPage to build a 360° Performance tool for my company, integrating
48
46
49
47
Here are some pages I built using only SQL queries, allowing everyone in the company to instantly access any level of information, from the fiscal year 2024 revenue trends to the top-selling products in Marseille in October 2022.
Copy file name to clipboardExpand all lines: examples/official-site/content/blog/how-to-use-the-pagination-component.md
+31-34Lines changed: 31 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
+
---
2
+
title: How to use the pagination component
3
+
date: '2025-11-10'
4
+
icon: sailboat-2
5
+
summary: A tutorial for using the pagination component
6
+
---
1
7
2
-
INSERT INTO blog_posts (title, description, icon, created_at, content)
3
-
VALUES
4
-
(
5
-
'How to use the pagination component',
6
-
'A tutorial for using the pagination component',
7
-
'sailboat-2',
8
-
'2025-11-10',
9
-
'
10
8
# How to use the pagination component
11
9
12
10
To display a large number of records from a database, it is often practical to split these data into pages. The user can thus navigate from one page to another, as well as directly to the first or last page. With SQLPage, it is possible to perform these operations using the pagination component.
@@ -34,17 +32,17 @@ SET pages_count = (CAST($records_count AS INTEGER) / CAST($MAX_RECORD_PER_PAGE A
34
32
```
35
33
36
34
It is possible that the number of rows in the table is greater than the estimated number of pages multiplied by the number of rows per page. In this case, it is necessary to add an additional page.
37
-
35
+
38
36
```
39
37
SET pages_count = (
40
-
CASE
41
-
WHEN MOD(CAST($records_count AS INTEGER),CAST($MAX_RECORD_PER_PAGE AS INTEGER)) = 0 THEN $pages_count
42
-
ELSE (CAST($pages_count AS INTEGER) + 1)
38
+
CASE
39
+
WHEN MOD(CAST($records_count AS INTEGER),CAST($MAX_RECORD_PER_PAGE AS INTEGER)) = 0 THEN $pages_count
40
+
ELSE (CAST($pages_count AS INTEGER) + 1)
43
41
END
44
42
);
45
43
```
46
44
47
-
We will need to transmit the page number to be displayed in the URL using the `page` parameter. We do the same for the number of the first page (`idx_page`) appearing at the left end of the pagination component.
45
+
We will need to transmit the page number to be displayed in the URL using the `page` parameter. We do the same for the number of the first page (`idx_page`) appearing at the left end of the pagination component.
48
46
49
47

50
48
@@ -58,15 +56,15 @@ SET idx_page = COALESCE($idx_page,1);
58
56
59
57
## Read the data
60
58
61
-
We can now read and display the data based on the active page. To do this, we simply use a table component.
59
+
We can now read and display the data based on the active page. To do this, we simply use a table component.
62
60
63
61
```
64
-
SELECT
65
-
''table'' as component;
66
62
SELECT
67
-
user_id AS id,
63
+
'table' as component;
64
+
SELECT
65
+
user_id AS id,
68
66
last_name AS "Last name",
69
-
first_name AS "First name"
67
+
first_name AS "First name"
70
68
FROM
71
69
users
72
70
ORDER BY user_id
@@ -89,13 +87,13 @@ SET previous_parameters = (
89
87
CASE
90
88
WHEN CAST($page AS INTEGER) > 1 THEN
91
89
json_object(
92
-
''page'', (CAST($page AS INTEGER) - 1),
93
-
''idx_page'', (CASE
90
+
'page', (CAST($page AS INTEGER) - 1),
91
+
'idx_page', (CASE
94
92
WHEN CAST($idx_page AS INTEGER) > 1 THEN (CAST($idx_page AS INTEGER) - 1)
95
93
ELSE $idx_page
96
-
END)
94
+
END)
97
95
)
98
-
ELSE json_object() END
96
+
ELSE json_object() END
99
97
);
100
98
```
101
99
@@ -106,11 +104,11 @@ SET next_parameters = (
106
104
CASE
107
105
WHEN CAST($page AS INTEGER) < CAST($pages_count AS INTEGER) THEN
108
106
json_object(
109
-
''page'', (CAST($page AS INTEGER) + 1),
110
-
''idx_page'', (CASE
107
+
'page', (CAST($page AS INTEGER) + 1),
108
+
'idx_page', (CASE
111
109
WHEN CAST($idx_page AS INTEGER) < (CAST($pages_count AS INTEGER) - CAST($MAX_PAGES AS INTEGER) + 1) THEN (CAST($idx_page AS INTEGER) + 1)
112
110
ELSE $idx_page
113
-
END)
111
+
END)
114
112
)
115
113
ELSE json_object() END
116
114
);
@@ -123,27 +121,27 @@ We can now add the pagination component, which is placed below the table display
123
121
124
122
```
125
123
SELECT
126
-
''pagination'' AS component,
124
+
'pagination' AS component,
127
125
(CAST($page AS INTEGER) = 1) AS first_disabled,
128
126
(CAST($page AS INTEGER) = 1) AS previous_disabled,
129
127
(CAST($page AS INTEGER) = CAST($pages_count AS INTEGER)) AS next_disabled,
130
128
(CAST($page AS INTEGER) = CAST($pages_count AS INTEGER)) AS last_disabled,
131
-
sqlpage.link(sqlpage.path(), json_object(''page'', 1, ''idx_page'', 1)) as first_link,
129
+
sqlpage.link(sqlpage.path(), json_object('page', 1, 'idx_page', 1)) as first_link,
132
130
sqlpage.link(sqlpage.path(), $previous_parameters) AS previous_link,
133
131
sqlpage.link(sqlpage.path(), $next_parameters) AS next_link,
WHEN (CAST($pages_count AS INTEGER) <= CAST($MAX_PAGES AS INTEGER)) THEN 1
139
-
ELSE (CAST($pages_count AS INTEGER) - CAST($MAX_PAGES AS INTEGER) + 1)
137
+
ELSE (CAST($pages_count AS INTEGER) - CAST($MAX_PAGES AS INTEGER) + 1)
140
138
END)
141
139
)
142
140
) AS last_link,
143
141
TRUE AS outline;
144
142
```
145
143
146
-
The final step is to generate the page numbers based on the number of pages and the index of the first page displayed to the left of the component. To do this, we use a recursive CTE query.
144
+
The final step is to generate the page numbers based on the number of pages and the index of the first page displayed to the left of the component. To do this, we use a recursive CTE query.
147
145
148
146
```
149
147
WITH RECURSIVE page_numbers AS (
@@ -155,12 +153,11 @@ WITH RECURSIVE page_numbers AS (
155
153
WHERE number < CAST($pages_count AS INTEGER)
156
154
LIMIT CAST($MAX_PAGES AS INTEGER)
157
155
)
158
-
SELECT
156
+
SELECT
159
157
number AS contents,
160
-
sqlpage.link(sqlpage.path(), json_object(''page'', number, ''idx_page'', $idx_page)) as link,
161
-
(number = CAST($page AS INTEGER)) AS active
158
+
sqlpage.link(sqlpage.path(), json_object('page', number, 'idx_page', $idx_page)) as link,
159
+
(number = CAST($page AS INTEGER)) AS active
162
160
FROM page_numbers;
163
161
```
164
162
165
163
If the added page matches the content of the `page` variable, the `active` option is set to `TRUE` so that the user knows it is the current page.
0 commit comments