Skip to content

Commit 608db2b

Browse files
committed
Store the official blog and site directories as editable documents
1 parent 0eaaca7 commit 608db2b

20 files changed

Lines changed: 2295 additions & 0 deletions
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: 3 solutions to the 3 layer problem
3+
date: '2023-08-10'
4+
icon: adjustments-question
5+
summary: What is the 3 layer problem, and how SQLPage solves it?
6+
---
7+
8+
# 3 solutions to the 3 layer problem
9+
10+
> Some interesting questions emerged from the article [Repeating yourself thrice doesn't turn you into a 3X developer](https://yrashk.medium.com/repeating-yourself-thrice-doesnt-turn-you-into-a-3x-developer-a778495229c0).
11+
> This short follow-up article aims to answer them and clarify some points.
12+
13+
Hello all,
14+
15+
I am Ophir Lojkine, the main contributor of the open-source application server **SQLPage**.
16+
17+
The previous article focused on the conventional model of splitting applications into three distinct tiers:
18+
19+
1. a graphical interface (_front-end_),
20+
2. an application server (_back-end_),
21+
3. and a database.
22+
23+
In many projects, this results in three distinct implementations of the application’s data model:
24+
25+
1. First, in SQL, in the form of tables, views, and relationships in the database,
26+
2. Then, in _server side_ languages such as Java, Python, or PHP, to create an API managing access to the data, and to implement the business logic of the application,
27+
3. Finally, in JavaScript or TypeScript to implement data manipulation in the user interface.
28+
29+
![Traditional tiers model](blog/three-layers.svg)
30+
31+
---
32+
33+
The topic of interest here is the duplication of the data model between the different layers,
34+
and the communication overhead between them.
35+
We are not talking about how the code is structured within each layer.
36+
It can follow a Model-View-Controller pattern or not, it doesn't matter.
37+
38+
This three-layer model has several advantages:
39+
specialization of the programmers,
40+
parallelization of work,
41+
scalability,
42+
separation of concerns,
43+
and an optimal exploitation of the capacities of the infrastructure on which each layer is deployed:
44+
web browser, server application and database.
45+
46+
Nevertheless, in large-scale projects,
47+
there is often a certain redundancy of the code between the different layers,
48+
as well as a non-negligible share of code dedicated to communication between them.
49+
For small teams and solo developers, this becomes a major drawback.
50+
51+
## 3 solutions
52+
53+
Fortunately, there are several approaches to solving this problem:
54+
55+
1. For **UI-centric applications** without complicated data processing needs,
56+
you can almost completely abandon server-side development and **directly expose the data to the frontend**.
57+
Open-source tools available in this space include Supabase, PocketBase or Hasura.
58+
2. For **applications with a predominant business logic**, traditional _web frameworks_
59+
solve this problem by centralizing frontend and database control in the backend code.
60+
A common solution involves using an ORM and templating system instead of a dedicated javascript application.
61+
Popular solutions include Django, Ruby on Rails, or Symphony.
62+
3. For simpler applications, it is possible to **avoid both backend and frontend development**
63+
by adopting a _database-first_ approach.
64+
This alternative, although less widespread, allows taking advantage of under-exploited modern capacities of relational databases.
65+
The purpose of the original article was to introduce this lesser known approach.
66+
* **SQLPage** is representative of this last category,
67+
which allows designing a complete web application _in SQL_.
68+
This leads to a loss of control over the precise visual appearance of the application,
69+
which will get a “standardized” look and feel.
70+
On the other hand, this translates into significant gains in terms of development speed,
71+
simplicity and performance.
72+
This solution is not intended to compete with traditional _frameworks_,
73+
but rather integrate earlier in the life cycle of a project.
74+
It thus makes it possible to quickly develop a data structure adapted to the application,
75+
and to iterate over it while benefiting from continuous visual feedback on the final result.
76+
Then, when the application grows, it’s easy to add a classic frontend and backend on top of the existing database,
77+
without having to start from scratch.
78+
79+
Whichever approach is chosen in the end,
80+
a solid understanding of the conventional three-tier architecture,
81+
as well as a clear perspective on the challenges it creates and the possible solutions,
82+
facilitates decision-making and the evolution of the project with the best suited technologies.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Come and see us in Athens !
3+
date: '2024-10-15'
4+
icon: microphone-2
5+
summary: PGConf 2024 is coming to Athens, Greece. And we will be there to talk about SQLPage & Archeology !
6+
---
7+
8+
# PostgreSQL & SQLPage at PGConf 2024
9+
10+
We have been invited to give a talk at PGConf 2024 in Athens, Greece.
11+
12+
Last year, we gave a general introduction to SQLPage at PGConf.eu 2023 in Prague.
13+
14+
This year, we will focus on a more specific use case:
15+
using SQLPage to build a power-tool for archaeologists to explore and understand archaeological sites,
16+
radically changing the way archaeologists work, and allowing them to
17+
drastically reduce the time spent on data entry and management.
18+
19+
There will be two presenters:
20+
- **Ophir Lojkine**, the creator and maintainer of SQLPage, will present the project and its capabilities.
21+
- **Thomas Guillemard**, an archaeologist from France's National Institute for Preventive Archaeological Research, will present the project's use case and its benefits.
22+
23+
Come and see us in Athens !
24+
25+
https://www.postgresql.eu/events/pgconfeu2024/schedule/session/5707-unearthing-the-past-with-postgresql-how-open-source-is-revolutionizing-digital-archaeology/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Come see me build twitter live on stage in Prague
3+
date: '2023-11-11'
4+
icon: calendar-event
5+
summary: I will speak about SQLPage at pgconf.eu in Prague on December 14th. Come see me !
6+
---
7+
8+
# SQLPage live on stage
9+
10+
Hello everyone !
11+
12+
If some of you european SQLPagers are around Prague this december,
13+
I will be giving a talk about SQLPage at [pgconf.eu](https://2023.pgconf.eu/) on December 14th.
14+
15+
I will be talking about website building in general, SQLPage in particular,
16+
cool things you can do with it,
17+
how it works, how and why I built it,
18+
and why I still think it can cut web development and prototyping times by a factor of 10.
19+
20+
I will also be building a tiny social network live on stage, using SQLPage.
21+
22+
Come see me !
23+
24+
- [pgconf.eu](https://2023.pgconf.eu/)
25+
- [Information about the talk](https://www.postgresql.eu/events/pgconfeu2023/schedule/session/4687-sqlpage-building-a-full-web-application-with-nothing-but-postgres-and-sql-queries/)
26+
- When ? **December 14th, 2023**, **09:30 - 10:20**
27+
- Where ? Zenit Room, [Clarion Congress Hotel, Prague, Czech Republic](https://maps.app.goo.gl/qHCAaRFRjXmx2kQA7)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
---
7+
8+
SQLPage uses a simple file-based routing system that maps URLs directly to SQL files in your project directory.
9+
No complex configuration is needed. Just create files and they become accessible endpoints.
10+
11+
This guide explains how SQLPage resolves URLs, handles different file types, and manages 404 errors so you can structure your application effectively.
12+
13+
## Request routing order
14+
15+
### 1. Site Prefix Handling
16+
17+
If you've configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
18+
SQLPage will redirect all requests that do not start with the prefix to `/<site_prefix>`.
19+
20+
### 2. Path Resolution Priority
21+
22+
**Directory requests (paths ending with `/`)**: SQLPage looks for an `index.sql` file in that directory and executes it if found.
23+
24+
**Direct SQL file requests (`.sql` extension)**: SQLPage executes the requested SQL file if it exists. The extension is matched without regard to ASCII letter case, so `/report.SQL` is also executed. It is never served as source text.
25+
26+
**Static asset requests (other extensions)**: SQLPage serves files like CSS, JavaScript, images, or any other static content directly.
27+
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.
29+
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.
31+
32+
### Error Handling
33+
34+
When, after applying each of the rules above in order, SQLPage can't find a requested file,
35+
it walks up your directory structure looking for [custom `404.sql` files](/your-first-sql-website/custom_urls).
36+
37+
## Dynamic Routing with SQLPage
38+
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:
40+
41+
### Product Catalog with Dynamic IDs
42+
43+
**Goal**: Handle URLs like `/products/123`, `/products/abc`, `/products/new-laptop`
44+
45+
**Setup**:
46+
```text
47+
products/
48+
├── index.sql # Lists all products (/products/)
49+
├── 404.sql # Handles /products/<product-id>
50+
└── categories.sql # Product categories (/products/categories)
51+
```
52+
53+
**Request paths**
54+
- `/products/` → Executes `products/index.sql` (product listing)
55+
- `/products/123` → No `123.sql` file exists, so executes `products/404.sql`
56+
- `/products/laptop` → No `laptop.sql` file exists, so executes `products/404.sql`
57+
58+
**In `products/404.sql`**:
59+
```sql
60+
set product_id = substr(sqlpage.path(), 1+length('/products/'));
61+
```

0 commit comments

Comments
 (0)