chore: import upstream snapshot with attribution
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# SQLPage application example
|
||||
|
||||
This is a very simple example of a website that uses the SQLPage web application framework.
|
||||
|
||||
This website illustrates how to create a basic Create-Read-Update-Delete (CRUD) application using SQLPage.
|
||||
It has the following bsic features:
|
||||
|
||||
- Displays a list of user names using the [list component](https://sql-page.com/documentation.sql?component=list#component) (in [`index.sql`](./index.sql#L14-L20))
|
||||
- Add a new user name to the list through a [form](https://sql-page.com/documentation.sql?component=form#component) (in [`index.sql`](./index.sql#L1-L9))
|
||||
- View a user's personal page by clicking on a name in the list (in [`user.sql`](./user.sql))
|
||||
- Delete a user from the list by clicking on the delete button in the user's personal page (in [`delete.sql`](./delete.sql))
|
||||
|
||||
## Running the example
|
||||
|
||||
To run the example, just launch the sqlpage binary from this directory.
|
||||
|
||||
## Files
|
||||
|
||||
- [`index.sql`](./index.sql): The main page of the website. Contains a form to add a new user and a list of all users.
|
||||
- [`user.sql`](./user.sql): The user's personal page. Contains a link to delete the user.
|
||||
- [`delete.sql`](./delete.sql): The page that deletes the user from the database, and the redirects to the main page.
|
||||
- [`sqlpage/migrations/001_create_users_table.sql`](./sqlpage/migrations/001_create_users_table.sql): The SQL migration that creates the users table in the database.
|
||||
- [`sqlpage/sqlpage.json`](./sqlpage/sqlpage.json): The [SQLPage configuration](../../configuration.md) file.
|
||||
@@ -0,0 +1,8 @@
|
||||
DELETE FROM users
|
||||
WHERE id = $id
|
||||
RETURNING
|
||||
'text' AS component,
|
||||
'
|
||||
The user ' || username || ' has been deleted.
|
||||
|
||||
[Back to the user list](index.sql)' as contents_md;
|
||||
@@ -0,0 +1,8 @@
|
||||
services:
|
||||
web:
|
||||
image: lovasoa/sqlpage:main
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- .:/var/www
|
||||
- ./sqlpage:/etc/sqlpage
|
||||
@@ -0,0 +1,8 @@
|
||||
update users
|
||||
set username = :Username,
|
||||
is_admin = :Administrator is not null
|
||||
where :Username is not null and id = $id;
|
||||
|
||||
select 'form' as component;
|
||||
select 'text' as type, 'Username' as name, username as value from users where id = $id;
|
||||
select 'checkbox' as type, 'Has administrator privileges' as label, 'Administrator' as name, is_admin as checked from users where id = $id;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- A form to create a new entry in the database
|
||||
SELECT 'form' AS component,
|
||||
'Add a user' AS title;
|
||||
SELECT 'Username' as name,
|
||||
TRUE as required;
|
||||
-- Handle the form results when present
|
||||
INSERT INTO users (username)
|
||||
SELECT :Username
|
||||
WHERE :Username IS NOT NULL;
|
||||
----------------------------------
|
||||
-- Display the list of users
|
||||
-- It is important that this query comes after the INSERT query above,
|
||||
-- so that the updated list is visible immediately
|
||||
SELECT 'list' AS component,
|
||||
'Users' AS title;
|
||||
SELECT username AS title,
|
||||
username || ' is a user on this website.' as description,
|
||||
case when is_admin then 'red' end as color,
|
||||
'user' as icon,
|
||||
'user.sql?id=' || id as link
|
||||
FROM users;
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
is_admin BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"database_url": "sqlite://:memory:"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
select 'table' as component, 'action' as markdown;
|
||||
select *,
|
||||
format('[Edit](edit.sql?id=%s)', id) as action
|
||||
from users;
|
||||
@@ -0,0 +1,47 @@
|
||||
GET http://localhost:8080/
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "Add a user"
|
||||
body contains "Users"
|
||||
body not contains "An error occurred"
|
||||
|
||||
POST http://localhost:8080/
|
||||
[FormParams]
|
||||
Username: Hurl User
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "Hurl User"
|
||||
body contains "user.sql?id"
|
||||
body not contains "An error occurred"
|
||||
|
||||
GET http://localhost:8080/user.sql?id=1
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "Hurl User"
|
||||
body contains "Edit user"
|
||||
body contains "Delete this user"
|
||||
body not contains "An error occurred"
|
||||
|
||||
POST http://localhost:8080/edit.sql?id=1
|
||||
[FormParams]
|
||||
Username: Hurl Admin
|
||||
Administrator: on
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "Hurl Admin"
|
||||
body contains "Has administrator privileges"
|
||||
body not contains "An error occurred"
|
||||
|
||||
GET http://localhost:8080/
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "Hurl Admin"
|
||||
body not contains "Hurl User is a user"
|
||||
body not contains "An error occurred"
|
||||
|
||||
GET http://localhost:8080/delete.sql?id=1
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
body contains "The user Hurl Admin has been deleted."
|
||||
body contains "Back to the user list"
|
||||
body not contains "An error occurred"
|
||||
@@ -0,0 +1,9 @@
|
||||
SELECT 'text' as component,
|
||||
username as title,
|
||||
username || ' is a user on this site.
|
||||
|
||||
[Delete this user](delete.sql?id=' || id || ')
|
||||
|
||||
[Edit user](edit.sql?id=' || id || ')' as contents_md
|
||||
FROM users
|
||||
WHERE id = $id;
|
||||
Reference in New Issue
Block a user