#web-framework #sql-query #sql #web #web-server #sql-database #build-web

bin+lib sqlpage

Build data user interfaces entirely in SQL. A web server that takes .sql files and formats the query result using pre-made configurable professional-looking components.

45 releases (21 breaking)

0.31.0 Nov 24, 2024
0.29.0 Sep 25, 2024
0.25.0 Jul 13, 2024
0.20.1 Mar 23, 2024
0.4.4 Jan 29, 2023

#75 in HTTP server

Download history 38/week @ 2024-08-19 143/week @ 2024-08-26 47/week @ 2024-09-02 29/week @ 2024-09-09 51/week @ 2024-09-16 179/week @ 2024-09-23 98/week @ 2024-09-30 27/week @ 2024-10-07 20/week @ 2024-10-14 41/week @ 2024-10-21 295/week @ 2024-10-28 33/week @ 2024-11-04 16/week @ 2024-11-11 150/week @ 2024-11-18 100/week @ 2024-11-25 284/week @ 2024-12-02

551 downloads per month

MIT license

430KB
10K SLoC

Rust 8K SLoC // 0.0% comments Handlebars 1.5K SLoC // 0.0% comments JavaScript 531 SLoC // 0.0% comments SQL 25 SLoC // 0.3% comments

SQLpage

A short video explaining the concept of sqlpage

SQLpage is an SQL-only webapp builder. It is meant for data scientists, analysts, and business intelligence teams to build powerful data-centric applications quickly, without worrying about any of the traditional web programming languages and concepts.

With SQLPage, you write simple .sql files containing queries to your database to select, group, update, insert, and delete your data, and you get good-looking clean webpages displaying your data as text, lists, grids, plots, and forms.

Examples

CodeResult
SELECT 
    'list' as component,
    'Popular websites' as title;
SELECT 
    name as title,
    url as link,
    CASE type
      WHEN 1 THEN 'blue'
      ELSE 'red'
    END as color,
    description, icon, active
FROM website;

SQLPage list component

SELECT
  'chart' as component,
  'Quarterly Revenue' as title,
  'area' as type;

SELECT
    quarter AS x,
    SUM(revenue) AS y
FROM finances
GROUP BY quarter

SQLPage list component

SELECT
    'form' as component,
    'User' as title,
    'Create new user' as validate;

SELECT
    name, type, placeholder,
    required, description
FROM user_form;

INSERT INTO user
SELECT $first_name, $last_name, $birth_date
WHERE $first_name IS NOT NULL;

SQLPage list component

select 'tab' as component, true as center;
select 'Show all cards' as title, '?' as link,
  $tab is null as active;
select
  format('Show %s cards', color) as title,
  format('?tab=%s', color) as link,
  $tab=color as active
from tab_example_cards
group by color; 


select 'card' as component;
select
  title, description, color
  image_url as top_image, link
from tab_example_cards
where $tab is null or $tab = color;

select
  'text' as component,
  sqlpage.read_file_as_text('footer.md') as contents_md

card component sql example

Supported databases

  • SQLite, including the ability to load extensions such as Spatialite.
  • PostgreSQL, and other compatible databases such as YugabyteDB, CockroachDB and Aurora.
  • MySQL, and other compatible databases such as MariaDB and TiDB.
  • Microsoft SQL Server, and all compatible databases and providers such as Azure SQL and Amazon RDS.

Get started

Read the official get started guide on SQLPage's website.

Using executables

The easiest way to get started is to download the latest release from the releases page.

  • Download the binary that corresponds to your operating system (linux, macos, or windows).
  • Uncompress it: tar -xzf sqlpage-*.tgz
  • Run it: ./sqlpage.bin

With docker

To run on a server, you can use the docker image:

  • Install docker
  • In a terminal, run the following command:
    • docker run -it --name sqlpage -p 8080:8080 --volume "$(pwd):/var/www" --rm lovasoa/sqlpage
    • ("$(pwd):/var/www" allows sqlpage to run sql files from your current working directory)
  • Create a file called index.sql with the contents from this example
  • Open https://localhost:8080 in your browser
  • Optionally, you can also mount a directory containing sqlpage's configuration file, custom components, and migrations (see configuration.md) to /etc/sqlpage in the container.
    • For instance, you can use:
      • docker run -it --name sqlpage -p 8080:8080 --volume "$(pwd)/source:/var/www" --volume "$(pwd)/configuration:/etc/sqlpage:ro" --rm lovasoa/sqlpage
    • And place your website in a folder named source and your sqlpage.json in a folder named configuration.
  • If you want to build your own docker image, taking the raw sqlpage image as a base is not recommended, since it is extremely stripped down and probably won't contain the dependencies you need. Instead, you can take debian as a base and simply copy the sqlpage binary from the official image to your own image:
    • FROM debian:stable-slim
      COPY --from=lovasoa/sqlpage:main /usr/local/bin/sqlpage /usr/local/bin/sqlpage
      

We provide compiled binaries only for the x86_64 architecture, but provide docker images for other architectures, including arm64 and armv7. If you want to run SQLPage on a Raspberry Pi or a cheaper ARM cloud instance, using the docker image is the easiest way to do it.

On Mac OS, with homebrew

An alternative for Mac OS users is to use SQLPage's homebrew package.

  • Install homebrew
  • In a terminal, run the following commands:
    • brew install sqlpage

How it works

architecture diagram

SQLPage is a web server written in rust and distributed as a single executable file. When it receives a request to a URL ending in .sql, it finds the corresponding SQL file, runs it on the database, passing it information from the web request as SQL statement parameters. When the database starts returning rows for the query, SQLPage maps each piece of information in the row to a parameter in one of its pre-defined components' templates, and streams the result back to the user's browser.

Examples

You can try all the examples online without installing anything on your computer using SQLPage's online demo on replit.

Configuration

SQLPage can be configured through either a configuration file placed in sqlpage/sqlpage.json or environment variables such as DATABASE_URL or LISTEN_ON.

For more information, read configuration.md.

Additionally, custom components can be created by placing .handlebars files in sqlpage/templates. Example.

HTTPS

SQLPage supports HTTP/2 and HTTPS natively and transparently. Just set SQLPAGE_HTTPS_DOMAIN=example.com, and SQLPage will automatically request a trusted certificate and start encrypting all your user's traffic with it. No tedious manual configuration for you, and no annoying "Connection is Not Secure" messages for your users !

Serverless

You can run SQLpage serverless by compiling it to an AWS Lambda function. An easy way to do so is using the provided docker image:

 docker build -t sqlpage-lambda-builder . -f lambda.Dockerfile --target builder
 docker run sqlpage-lambda-builder cat deploy.zip > sqlpage-aws-lambda.zip

You can then just add your own SQL files to sqlpage-aws-lambda.zip, and upload it to AWS Lambda, selecting Custom runtime on Amazon Linux 2 as a runtime.

Hosting sql files directly inside the database

When running serverless, you can include the SQL files directly in the image that you are deploying. But if you want to be able to update your sql files on the fly without creating a new image, you can store the files directly inside the database, in a table that has the following structure:

CREATE TABLE sqlpage_files(
  path VARCHAR(255) NOT NULL PRIMARY KEY,
  contents BLOB,
  last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Make sure to update last_modified every time you update the contents of a file (or do it inside a TRIGGER). SQLPage will re-parse a file from the database only when it has been modified.

Technologies and libraries used

  • actix web handles HTTP requests at an incredible speed,
  • tabler handles the styling for professional-looking clean components,
  • tabler icons is a large set of icons you can select directly from your SQL,
  • handlebars render HTML pages from readable templates for each component.

Frequently Asked Questions

Why use SQL instead of a real programming language? SQL isn't even Turing-complete!

  • You're focusing on the wrong issue. If you can express your application declaratively, you should—whether using SQL or another language. Declarative code is often more concise, readable, easier to reason about, and easier to debug than imperative code.
  • SQL is simpler than traditional languages, often readable by non-programmers, yet very powerful.
  • If complexity is your goal, note that SQL is actually Turing-complete.
  • Even without recursive queries, a sequence of SQL statements driven by user interactions (like SQLPage) would still be Turing-complete, enabling you to build a SQL-powered website that functions as a Turing machine.

Just Because You Can Doesn’t Mean You Should...
someone being mean on Reddit

It's not about "should" — it's about "why not?" Keep coloring inside the lines if you want, but we'll be over here having fun with our SQL websites.

Is this the same as Microsoft Access?

The goals are similar — creating simple data-centric applications — but the tools differ significantly:

  • SQLPage is a web server, not a desktop app.
  • SQLPage connects to existing robust relational databases; Access tries to be a database.
  • Access is expensive and proprietary; SQLPage is open-source.
  • SQLPage spares you from the torment of Visual Basic for Applications.

Is the name a reference to Microsoft FrontPage?

FrontPage was a visual static website builder popular in the late '90s. I hadn't heard of it until someone asked.

I like CSS. I want to design websites, not write SQL.

If you want to write your own HTML and CSS, you can create custom components by adding a .handlebars file in sqlpage/templates and writing your HTML and CSS there. (Example). You can also use the html component to write raw HTML, or the shell component to include custom scripts and styles.

But SQLPage believes you shouldn't worry about button border radii until you have a working prototype. We provide good-looking components out of the box so you can focus on your data model, and iterate quickly.

Download

SQLPage is available for download on the from multiple sources:

GitHub Downloads (all assets, all releases) Docker Pulls homebrew downloads Scoop Version Crates.io Total Downloads

Contributing

We welcome contributions! SQLPage is built with Rust and uses vanilla javascript for its frontend parts.

Check out our Contributing Guide for detailed instructions on development setup, testing, and pull request process.

Dependencies

~85MB
~1.5M SLoC