Show HN: SQLPage – Build Dynamic Websites with Just SQL Queries (sql.ophir.dev)
Hey Hacker News!
I wanted to share the open source project I have been working on during the last year: SQLPage, a tool to build small web applications entirely in SQL.
Building web applications with just SQL isn't as crazy as it seems. Most simple applications can be expressed declaratively as just data queries that fill pre-defined web components.
I'd love to hear your feedback and thoughts on it. Would you potentially use it? How can it be improved?
Website: https://sql.ophir.dev/ Github: https://github.com/lovasoa/SQLpage Example app: https://conundrum.ophir.dev/
27 comments
[ 1.1 ms ] story [ 84.5 ms ] threadI mean I have some familiarity with "dynamic websites" and "just SQL Queries" but no clear picture of the mechanics.
When I hit a landing page, my first questions are:
I clicked "try it out" but it didn't start to answer my questions...instead it asked me questions.Anyway, Congratulations on launching. I know that's hard.
The diagram is a good idea, I'll do it. For a simple explanation, what do you think about:
I'll work on it.
Shameless plug: https://jinj.at
Any instructions for prod deployment?
Also an example project with Fly.io integration: https://github.com/jinjat-data/jaffle_shop_metrics
I'm actively working on the project so any feedback is welcome!
Then, you can make subsequent queries that can return multiple rows, and fill the component with data, displayed inside the piece of UI created by the component.
For instance, you can run
This will open a list component. Then will populate the list with entries from your interesting_topics database table.About putting all the app logic in SQL queries: yes, there are some apps that would be very hard, or impossible to build in SQLPage. But for most simple Create-Read-Update-Delete apps, you don't really have any complicated business logic, and not having ANY boilerplate to get started is I think what makes SQLPage compelling. And when your app later grows to have more complex business logic, you just move from SQLPage to a full-fledged backend framework, but you don't lose the work you have already done structuring your database schema and the core queries that your app will need.
The goal of SQLPage is not to replace something like Django, for instance. It is for django developers to be able to quickly test out their app idea, and for people who have no idea what "backend development" even means to still be able to create simple apps.
I really love the idea of having "virgin" SQL statements to get and set the data - doing all the JOINs etc in SQL so I can pull together the view I want from a few interlinked tables. The low effort declarative GUI which interacts with that is nice. It's super-powerful to be able to describe a CRUD app as a set of relational tables, and a set of SQL insert/select statements, and then a very lightweight declarative GUI to start modifying and reading data from it. Then if the app becomes important you can take the same underlying data structure and wrap it in a more established framework with a "real" front end. And if it doesn't, you only spent a few hours on it!
A few thoughts:
1. It took me a while to work out how to render anything. Maybe make the first example you hit in the "Your website's first SQL file" section actually have everything needed to render a page (including "select 'shell' as component")
2. More examples! Maybe a straightforward CRUD type example would be good - it took me a while to work out how to create a row.
3. I want a searchable table of database items with a way to edit each one - maybe an extension to the table view? Either a way to add a custom link to each row in the table, or an extension to it that allows editing of data. That's where a CRUD example would be good.
4. The form should have an input type "multi" which is constrained to the options I've queried from the database. That way I can use the form to insert relational data, or limit users to a set of selections.
5. The "checkbox" type is either whatever it's value is, or NULL. If I've got an integer not null type in the database, I have to coalesce($myCheckbox, 0) when saving it - can you make it have a default unchecked value?
6. The examples are all hard coded data - can you have more examples that use the result of database queries to get the data that's rendered?
It's a fun project though! I like how lightweight it is as well.
Can you list the step you took, starting from opening the website, and where the first pain points were ? Did you go sql.ophir.dev -> Get started -> technical, then downloaded the binary, wrote the first select, and hit a wall ? What did you do then ? What is the app you were trying to build ?
Simple pages without an explicit 'shell' component were always supposed to work, but they were not tested ! I fixed that in v0.6.8
https://github.com/lovasoa/SQLpage/commit/f91f0d57c39360e560...
Thank you !
My github sponsors page is opened at https://github.com/sponsors/lovasoa
You can also leave your email on https://docs.google.com/forms/d/1t91PI0vF5HyghshkGBONbdk6BvM... to get updates about the project, and the coming hosted SQLPage service.
Would you be interested in supporting PRQL (prql-lang.org)? The compiler is also written in rust so integration should be straightforward.
Disclaimer: I'm a contributor.
Github: github.com/PRQL/prql
Yes, absolutely! PRQL supports having a version and target header in the first line so you could make that mandatory for PRQL queries and only if it finds that then it routes it to the prql-compiler. Here's an example header:
> First, prql would need to support insert and update statements, though.Ah, I didn't spot that in your README examples. We don't have any plans to support those at the moment. PRQL aims to be an excellent query language and to focus on that solely (unix philosophy and all that).
What do you need inserts and updates for? To make a full CRUD app?
It might be convenient just to support PRQL for the query and Read parts and leave the CUD to SQL, if you felt so inclined of course.
Anyway, thanks for the reply. I'll play around with SQLPage for a bit and then we can chat again.
For the header, I don't think that would be necessary. SQLPage would route queries to .sql pages to the SQL parser and queries to .prql files to the prql parser.
If you want to play around with integrating prql in sqlpage, you can have a look at https://github.com/lovasoa/SQLpage/blob/main/src/webserver/d... This is a short self-contained rust file, and think you would not need to change anything more to interface with a prql parser. If you want to give it a stab, feel free to make a POC and get in touch :)