Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/official-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ select 'html' as language, '<h1>Hello</h1>' as contents;

Run `npm run site:test` to build the site, check its search index and published SQL, and run the documentation parser tests. Run `npm run site` to preview the site.

## Blog posts

Edit posts in [`sqlpage/content/blog/`](sqlpage/content/blog/). Start with YAML
front matter containing `title`, `date` (YYYY-MM-DD), `icon`, and `summary`,
then write the article in Markdown. Use `external_url` for posts published
elsewhere. Keep the title of a published post to preserve its permalink.

## Landing page

The home page is rendered by `index.sql` and the `landing-page` custom template.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: 3 solutions to the 3 layer problem
date: '2023-08-10'
icon: adjustments-question
summary: What is the 3 layer problem, and how SQLPage solves it?
---

# 3 solutions to the 3 layer problem

> 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).
> This short follow-up article aims to answer them and clarify some points.

Hello all,

I am Ophir Lojkine, the main contributor of the open-source application server **SQLPage**.

The previous article focused on the conventional model of splitting applications into three distinct tiers:

1. a graphical interface (_front-end_),
2. an application server (_back-end_),
3. and a database.

In many projects, this results in three distinct implementations of the application’s data model:

1. First, in SQL, in the form of tables, views, and relationships in the database,
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,
3. Finally, in JavaScript or TypeScript to implement data manipulation in the user interface.

![Traditional tiers model](blog/three-layers.svg)

---

The topic of interest here is the duplication of the data model between the different layers,
and the communication overhead between them.
We are not talking about how the code is structured within each layer.
It can follow a Model-View-Controller pattern or not, it doesn't matter.

This three-layer model has several advantages:
specialization of the programmers,
parallelization of work,
scalability,
separation of concerns,
and an optimal exploitation of the capacities of the infrastructure on which each layer is deployed:
web browser, server application and database.

Nevertheless, in large-scale projects,
there is often a certain redundancy of the code between the different layers,
as well as a non-negligible share of code dedicated to communication between them.
For small teams and solo developers, this becomes a major drawback.

## 3 solutions

Fortunately, there are several approaches to solving this problem:

1. For **UI-centric applications** without complicated data processing needs,
you can almost completely abandon server-side development and **directly expose the data to the frontend**.
Open-source tools available in this space include Supabase, PocketBase or Hasura.
2. For **applications with a predominant business logic**, traditional _web frameworks_
solve this problem by centralizing frontend and database control in the backend code.
A common solution involves using an ORM and templating system instead of a dedicated javascript application.
Popular solutions include Django, Ruby on Rails, or Symphony.
3. For simpler applications, it is possible to **avoid both backend and frontend development**
by adopting a _database-first_ approach.
This alternative, although less widespread, allows taking advantage of under-exploited modern capacities of relational databases.
The purpose of the original article was to introduce this lesser known approach.
* **SQLPage** is representative of this last category,
which allows designing a complete web application _in SQL_.
This leads to a loss of control over the precise visual appearance of the application,
which will get a “standardized” look and feel.
On the other hand, this translates into significant gains in terms of development speed,
simplicity and performance.
This solution is not intended to compete with traditional _frameworks_,
but rather integrate earlier in the life cycle of a project.
It thus makes it possible to quickly develop a data structure adapted to the application,
and to iterate over it while benefiting from continuous visual feedback on the final result.
Then, when the application grows, it’s easy to add a classic frontend and backend on top of the existing database,
without having to start from scratch.

Whichever approach is chosen in the end,
a solid understanding of the conventional three-tier architecture,
as well as a clear perspective on the challenges it creates and the possible solutions,
facilitates decision-making and the evolution of the project with the best suited technologies.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
title: Come and see us in Athens !
date: '2024-10-15'
icon: microphone-2
summary: PGConf 2024 is coming to Athens, Greece. And we will be there to talk about SQLPage & Archeology !
---

INSERT INTO blog_posts (title, description, icon, created_at, content)
VALUES
(
'Come and see us in Athens !',
'PGConf 2024 is coming to Athens, Greece. And we will be there to talk about SQLPage & Archeology !',
'microphone-2',
'2024-10-15',
'
# PostgreSQL & SQLPage at PGConf 2024

We have been invited to give a talk at PGConf 2024 in Athens, Greece.
Expand All @@ -20,9 +18,8 @@ drastically reduce the time spent on data entry and management.

There will be two presenters:
- **Ophir Lojkine**, the creator and maintainer of SQLPage, will present the project and its capabilities.
- **Thomas Guillemard**, an archaeologist from France''s National Institute for Preventive Archaeological Research, will present the project''s use case and its benefits.
- **Thomas Guillemard**, an archaeologist from France's National Institute for Preventive Archaeological Research, will present the project's use case and its benefits.

Come and see us in Athens !

https://www.postgresql.eu/events/pgconfeu2024/schedule/session/5707-unearthing-the-past-with-postgresql-how-open-source-is-revolutionizing-digital-archaeology/
');
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
INSERT INTO blog_posts (title, description, icon, created_at, content)
VALUES (
'Come see me build twitter live on stage in Prague',
'I will speak about SQLPage at pgconf.eu in Prague on December 14th. Come see me !',
'calendar-event',
'2023-11-11',
'
---
title: Come see me build twitter live on stage in Prague
date: '2023-11-11'
icon: calendar-event
summary: I will speak about SQLPage at pgconf.eu in Prague on December 14th. Come see me !
---

# SQLPage live on stage

Hello everyone !
Expand All @@ -25,5 +25,3 @@ Come see me !
- [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/)
- When ? **December 14th, 2023**, **09:30 - 10:20**
- Where ? Zenit Room, [Clarion Congress Hotel, Prague, Czech Republic](https://maps.app.goo.gl/qHCAaRFRjXmx2kQA7)

');
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
title: File-based routing in SQLPage
date: '2025-07-28'
icon: route
summary: Understanding how SQLPage maps URLs to files and handles errors
---

INSERT INTO blog_posts (title, description, icon, created_at, content)
VALUES
(
'File-based routing in SQLPage',
'Understanding how SQLPage maps URLs to files and handles errors',
'route',
'2025-07-28',
'
SQLPage uses a simple file-based routing system that maps URLs directly to SQL files in your project directory.
No complex configuration is needed. Just create files and they become accessible endpoints.

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

### 1. Site Prefix Handling

If you''ve configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
If you've configured a [`site_prefix`](/your-first-sql-website/nginx) in your settings,
SQLPage will redirect all requests that do not start with the prefix to `/<site_prefix>`.

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

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

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

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.

### Error Handling

When, after applying each of the rules above in order, SQLPage can''t find a requested file,
When, after applying each of the rules above in order, SQLPage can't find a requested file,
it walks up your directory structure looking for [custom `404.sql` files](/your-first-sql-website/custom_urls).

## Dynamic Routing with SQLPage

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

### Product Catalog with Dynamic IDs

Expand All @@ -59,7 +57,5 @@ products/

**In `products/404.sql`**:
```sql
set product_id = substr(sqlpage.path(), 1+length(''/products/''));
set product_id = substr(sqlpage.path(), 1+length('/products/'));
```
'
);
Loading
Loading