Skip to content

Commit 3bc22e2

Browse files
committed
Move the remaining blog tutorials and case studies to Markdown
1 parent a049411 commit 3bc22e2

8 files changed

Lines changed: 185 additions & 207 deletions

‎examples/official-site/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ live examples using SQLPage's stock theme. For example, visit
3030
Write posts in `content/blog/` as Markdown with YAML metadata: `title`, `date`
3131
(quoted as `YYYY-MM-DD`), `icon`, and `summary`. For a link to a post elsewhere,
3232
set `external_url` and omit the body. The title is the public URL key, so keep it
33-
when editing an existing post. Older posts are still in the SQL migrations.
33+
when editing an existing post.
3434

3535
## Landing page
3636

examples/official-site/sqlpage/migrations/64_blog_routing.sql renamed to examples/official-site/content/blog/file-based-routing-in-sqlpage.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff 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+
---
17

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-
'
108
SQLPage uses a simple file-based routing system that maps URLs directly to SQL files in your project directory.
119
No complex configuration is needed. Just create files and they become accessible endpoints.
1210

@@ -16,7 +14,7 @@ This guide explains how SQLPage resolves URLs, handles different file types, and
1614

1715
### 1. Site Prefix Handling
1816

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,
2018
SQLPage will redirect all requests that do not start with the prefix to `/<site_prefix>`.
2119

2220
### 2. Path Resolution Priority
@@ -27,18 +25,18 @@ SQLPage will redirect all requests that do not start with the prefix to `/<site_
2725

2826
**Static asset requests (other extensions)**: SQLPage serves files like CSS, JavaScript, images, or any other static content directly.
2927

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.
3129

3230
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.
3331

3432
### Error Handling
3533

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,
3735
it walks up your directory structure looking for [custom `404.sql` files](/your-first-sql-website/custom_urls).
3836

3937
## Dynamic Routing with SQLPage
4038

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:
4240

4341
### Product Catalog with Dynamic IDs
4442

@@ -59,7 +57,5 @@ products/
5957

6058
**In `products/404.sql`**:
6159
```sql
62-
set product_id = substr(sqlpage.path(), 1+length(''/products/''));
60+
set product_id = substr(sqlpage.path(), 1+length('/products/'));
6361
```
64-
'
65-
);

examples/official-site/sqlpage/migrations/45_blog_archeology.sql renamed to examples/official-site/content/blog/how-archaeology-is-gradually-entering-the-era-of-free-software.md

Lines changed: 19 additions & 23 deletions
Large diffs are not rendered by default.

examples/official-site/sqlpage/migrations/54_blog_bompard.sql renamed to examples/official-site/content/blog/how-i-built-a-360-performance-monitoring-tool-with-sql-queries.md

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff 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+
---
17

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-
'
108
# How I Built And Deployed An Exhaustive Performance Monitoring Tool For a 100M€/year Company Using SQL Queries Only
119

1210
### Building web applications in SQL
@@ -48,12 +46,12 @@ I am using SQLPage to build a 360° Performance tool for my company, integrating
4846

4947
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.
5048

51-
![](https://cdn-images-1.medium.com/max/800/1*MkORbAC7oGEG-8I1mthu6A.png)
52-
49+
![](https://cdn-images-1.medium.com/max/800/1*MkORbAC7oGEG-8I1mthu6A.png)\
50+
5351
*Performance of different channels vs last year and best sellers.
5452

55-
![](https://cdn-images-1.medium.com/max/800/1*_3-g1om_p9ghXhdcw0zHmw.png)
56-
53+
![](https://cdn-images-1.medium.com/max/800/1*_3-g1om_p9ghXhdcw0zHmw.png)\
54+
5755
*Examples of views built with SQLPage to provide a 360° tool for the company.
5856

5957
### Populating a chart from a query
@@ -68,27 +66,27 @@ You can find the full list of components: [https://sql-page.com/documentation.sq
6866

6967
Here’s an example of a parameterized SQL query that uses the “chart” component, along with the query to feed data into it:
7068

71-
72-
73-
```sql
74-
-- Chart Component
75-
SELECT ''chart'' AS component,
76-
CONCAT(''Daily Revenue from '', $start_date_comparison, '' to '', $end_date_comparison) AS title,
77-
''area'' AS type,
78-
''indigo'' AS color,
79-
5 AS marker,
80-
0 AS ymin;
81-
82-
-- Chart Data Query
83-
SELECT DATE(business_date) AS x,
84-
ROUND(SUM(value), 2) AS y
85-
FROM data_example
86-
WHERE DATE(business_date) BETWEEN $start_date_comparison AND $end_date_comparison
87-
AND variable_name = ''CA''
88-
GROUP BY DATE(business_date)
89-
ORDER BY x ASC;
90-
91-
-- NB: The variables $start_date_comparison and $end_date_comparison are
69+
70+
71+
```sql
72+
-- Chart Component
73+
SELECT 'chart' AS component,
74+
CONCAT('Daily Revenue from ', $start_date_comparison, ' to ', $end_date_comparison) AS title,
75+
'area' AS type,
76+
'indigo' AS color,
77+
5 AS marker,
78+
0 AS ymin;
79+
80+
-- Chart Data Query
81+
SELECT DATE(business_date) AS x,
82+
ROUND(SUM(value), 2) AS y
83+
FROM data_example
84+
WHERE DATE(business_date) BETWEEN $start_date_comparison AND $end_date_comparison
85+
AND variable_name = 'CA'
86+
GROUP BY DATE(business_date)
87+
ORDER BY x ASC;
88+
89+
-- NB: The variables $start_date_comparison and $end_date_comparison are
9290
-- defined dynamically in the SQL script
9391
```
9492
And the result:
@@ -138,4 +136,3 @@ What all these projects have in common is that they were built by a single perso
138136
- 📹Youtube tutorial videos on SQLPage channel: [https://www.youtube.com/@SQLPage/playlists](https://www.youtube.com/@SQLPage/playlists)
139137
- 🤓github: [https://github.com/sqlpage/SQLPage/](https://github.com/sqlpage/SQLPage/)
140138
- ☁️Host your applications: [https://datapage.app](https://datapage.app)
141-
');

examples/official-site/sqlpage/migrations/71_blog_pagination.sql renamed to examples/official-site/content/blog/how-to-use-the-pagination-component.md

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff 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+
---
17

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-
'
108
# How to use the pagination component
119

1210
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
3432
```
3533

3634
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+
3836
```
3937
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)
4341
END
4442
);
4543
```
4644

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.
4846

4947
![Meaning of URL parameters](blog/pagination.png)
5048

@@ -58,15 +56,15 @@ SET idx_page = COALESCE($idx_page,1);
5856

5957
## Read the data
6058

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.
6260

6361
```
64-
SELECT
65-
''table'' as component;
6662
SELECT
67-
user_id AS id,
63+
'table' as component;
64+
SELECT
65+
user_id AS id,
6866
last_name AS "Last name",
69-
first_name AS "First name"
67+
first_name AS "First name"
7068
FROM
7169
users
7270
ORDER BY user_id
@@ -89,13 +87,13 @@ SET previous_parameters = (
8987
CASE
9088
WHEN CAST($page AS INTEGER) > 1 THEN
9189
json_object(
92-
''page'', (CAST($page AS INTEGER) - 1),
93-
''idx_page'', (CASE
90+
'page', (CAST($page AS INTEGER) - 1),
91+
'idx_page', (CASE
9492
WHEN CAST($idx_page AS INTEGER) > 1 THEN (CAST($idx_page AS INTEGER) - 1)
9593
ELSE $idx_page
96-
END)
94+
END)
9795
)
98-
ELSE json_object() END
96+
ELSE json_object() END
9997
);
10098
```
10199

@@ -106,11 +104,11 @@ SET next_parameters = (
106104
CASE
107105
WHEN CAST($page AS INTEGER) < CAST($pages_count AS INTEGER) THEN
108106
json_object(
109-
''page'', (CAST($page AS INTEGER) + 1),
110-
''idx_page'', (CASE
107+
'page', (CAST($page AS INTEGER) + 1),
108+
'idx_page', (CASE
111109
WHEN CAST($idx_page AS INTEGER) < (CAST($pages_count AS INTEGER) - CAST($MAX_PAGES AS INTEGER) + 1) THEN (CAST($idx_page AS INTEGER) + 1)
112110
ELSE $idx_page
113-
END)
111+
END)
114112
)
115113
ELSE json_object() END
116114
);
@@ -123,27 +121,27 @@ We can now add the pagination component, which is placed below the table display
123121

124122
```
125123
SELECT
126-
''pagination'' AS component,
124+
'pagination' AS component,
127125
(CAST($page AS INTEGER) = 1) AS first_disabled,
128126
(CAST($page AS INTEGER) = 1) AS previous_disabled,
129127
(CAST($page AS INTEGER) = CAST($pages_count AS INTEGER)) AS next_disabled,
130128
(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,
132130
sqlpage.link(sqlpage.path(), $previous_parameters) AS previous_link,
133131
sqlpage.link(sqlpage.path(), $next_parameters) AS next_link,
134132
sqlpage.link(
135133
sqlpage.path(),
136-
json_object(''page'', $pages_count, ''idx_page'', (
134+
json_object('page', $pages_count, 'idx_page', (
137135
CASE
138136
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)
140138
END)
141139
)
142140
) AS last_link,
143141
TRUE AS outline;
144142
```
145143

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.
147145

148146
```
149147
WITH RECURSIVE page_numbers AS (
@@ -155,12 +153,11 @@ WITH RECURSIVE page_numbers AS (
155153
WHERE number < CAST($pages_count AS INTEGER)
156154
LIMIT CAST($MAX_PAGES AS INTEGER)
157155
)
158-
SELECT
156+
SELECT
159157
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
162160
FROM page_numbers;
163161
```
164162

165163
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.
166-
');

0 commit comments

Comments
 (0)