Project Icon

SQLpage

SQL驱动的快速Web应用构建工具

SQLpage是一款SQL驱动的Web应用构建工具,让数据专业人员无需Web编程知识即可快速开发数据应用。支持多种数据库,提供丰富组件,简化数据可视化和交互流程。

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 would I want to write SQL instead of a real programming language? SQL is not even Turing-complete!

  • You are probably worrying about the wrong thing. If you can express your application in a purely declarative manner, you should propably do it, even if you are using a traditional programming language. It will be much more concise, readable, easy to reason about and to debug than any imperative code you could write.
  • SQL is much more simple than traditional programming languages. It is often readable even by non-programmers, and yet it is very powerful.
  • If you really want to make your website more complicated than it needs to be, please note that SQL is actually Turing-complete.
  • Even if it wasn't (if it didn't have recursive queries), a sequence of SQL statement executions driven by an user, like SQLPage allows you to do, would still be Turing-complete. You could build a sql website representing a Turing machine where the user would have to click "next" repeatedly to compute the next state of the machine.

Just Because You Can Doesn’t Mean You Should...

someone being mean on reddit

Life's too short to always play it safe. Where's the fun in should? I think SQLPage has some real value to offer, despite its unconventional approach ! SQLPage isn't intended to replace traditional web development frameworks or discourage their usage. Instead, it caters to a specific group of people who want to leverage their SQL skills to rapidly build web applications, without spending months learning all of the technologies involved in traditional web development, and then weeks using them to build a simple CRUD application.

Is this the same as Microsoft Access?

The goal is the same: make it easy to create simple data-centric applications. But the tools are very different:

Is the name a reference to Microsoft Frontpage ?

Frontpage was a visual static website building software popular in the late 90s. I had never heard of it before someone asked me this question.

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

Are you human ? Human beings hate CSS.

The take of SQLPage is that you should not spend time designing the border radius of your buttons until you have a working prototype. We provide a set of components that look decent out of the box, so that you can focus on your data model instead.

However, if you really want to write your own HTML and CSS, you can do it by creating your own components. Just create a .handlebars file in sqlpage/templates and write your HTML and CSS in it. (example)

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

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号