What is SQLPage?
main.sql files and automatically renders the results using built-in web components such as tables, lists, forms, and plots. This eliminates the need to write HTML, CSS, or JavaScript for many application types.repository·main·Indexed 25 days ago
https://github.com/sqlpage/sqlpageSQLPage is an SQL-only webapp builder and web server that transforms database queries into interactive, data-centric websites. It allows developers to build user interfaces—including lists, charts, forms, and dashboards—entirely in SQL files using pre-made configurable components. Version 0.45.0 supports features such as lazy-loading remote pages into cards, reusable code modules via sqlpage.run_sql(), and comprehensive patterns for implementing authentication and CRUD applications.
.sql files and automatically renders the results using built-in web components such as tables, lists, forms, and plots. This eliminates the need to write HTML, CSS, or JavaScript for many application types.scripts/ directory contains specialized scripts used during the Docker build process to enable cross-compilation for SQLPage. These scripts manage the complexities of building for different architectures (such as amd64, arm64, and arm) by handling system dependencies, cross-compiler installation, and library extraction required for the runtime environment.shell component allows you to define a consistent look and feel (like headers and navigation) across multiple pages. In this example, website_header.json defines a shell that is applied to all pages rendered via the dynamic component, ensuring a unified user interface.A static simple select is a highly restricted SELECT statement that SQLPage executes internally without contacting your database. This is faster for trivial data needs.
To be considered a static simple select, the statement must:
FROM, WHERE, GROUP BY, ORDER BY, LIMIT, WITH, etc.value AS alias.NULL) or variables ($name, :message) as values.SELECT 'text' AS component, 'Hello' AS contents;
SELECT 'text' AS component, $name AS contents;-- String concatenation requires the database
select 'from' as component, 'handle_form.sql?id=' || $id as action;
-- WHERE clause requires the database
select 'text' as component, $alert_message as contents where $should_alert;
-- Database functions require the database
SELECT CURRENT_TIMESTAMP AS now;shell.sql file. This file acts as a wrapper or template that includes your page-specific content. You can combine this with the sqlpage.run_sql function to dynamically inject components or content into your common layout.To avoid duplicating authentication or header logic across multiple pages, place common code in a separate .sql file and execute it using the sqlpage.run_sql() function within a dynamic component.
Variables set in the calling page (like $_session_required) are accessible within the loaded module. This allows you to control the behavior of the module based on the context of the page that calls it.
set _curpath = sqlpage.path();
set _session_required = 1;
SELECT
'dynamic' AS component,
sqlpage.run_sql('header_shell_session.sql') AS properties;A data-centric application in SQLPage can be organized into specialized modules to separate concerns. A common pattern for a single entity (e.g., "currencies") involves three types of modules:
table component. It often includes an "actions" column (rendered as markdown) with shortcuts to edit or delete records.datagrid component). It handles logic for both existing records (via an id parameter) and new records.$_shell_enabled flag.SQLPage acts as a bridge between untyped HTTP requests and typed databases.
[] (e.g., user[]=Tim&user[]=Tom), SQLPage converts it into a JSON string: '["Tim", "Tom"]'. This can be parsed using your database's JSON functions.TEXT/VARCHAR) or NULL.Each row returned by the database is converted into a JSON object for components:
SELECT
1 AS one,
'x' AS my_array, 'y' AS my_array,
now() AS today,
'<svg></svg>'::bytea AS my_image;Resulting JSON:
{
"one": 1,
"my_array": ["x", "y"],
"today": "2025-08-30T06:40:13.894918+00:00",
"my_image": "data:image/svg+xml;base64,PHN2Zz48L3N2Zz48L3N2Zy4+"
}SQLPage provides several key capabilities for rapid application development:
You can store each user answer in a cookie using the cookie component and retrieve it on the next step using the sqlpage.cookie function.
Pros:
form component.Cons:
dynamic component can be used to create single-page applications or complex layouts where multiple forms or elements exist on one page. In this example, admin.sql uses the dynamic component to generate a single page that renders one form for every Multiple Choice Question (MCQ) option available in the database.SQLPage processes your .sql files by reading and executing one statement at a time. For each statement, SQLPage makes a decision:
JOIN, WHERE, GROUP BY, ORDER BY, subqueries, or database-specific functions (e.g., CURRENT_TIMESTAMP).sqlpage.* functions are always executed by SQLPage, never by your database. They can be used as input values (evaluated before the query) or as top-level selected columns (applied per row after the query).