Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/official-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ It is hosted as a simple Docker container on [sql-page.com](https://sql-page.com

Feel free to [open a pull request](https://github.com/lovasoa/sqlpage/pulls) if you would like to add or change anything !

## Guide and example directories

Edit [`guides.yaml`](sqlpage/content/guides.yaml) to change the guide list.
Use `sort_order` to set its display order. Edit
[`projects.yaml`](sqlpage/content/projects.yaml) to update the example directory.
Each `folder` must match a directory name under [`examples/`](../) exactly.

## Preview and deployment

Run `npm ci --ignore-scripts` from the repository root, then `npm run site`.
Expand Down
29 changes: 29 additions & 0 deletions examples/official-site/sqlpage/content/guides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
entries:
- sort_order: 1
title: Your first website
link: /your-first-sql-website/
description: Install SQLPage and build a website from a SQL file.
- sort_order: 2
title: SQL and variables
link: /extensions-to-sql.sql
description: Read request parameters, set variables, and call SQLPage functions.
- sort_order: 3
title: Custom components
link: /custom_components.sql
description: Render your own HTML with Handlebars templates.
- sort_order: 4
title: Database migrations
link: /your-first-sql-website/migrations.sql
description: Create and update your database schema with versioned SQL files.
- sort_order: 5
title: Custom URLs
link: /your-first-sql-website/custom_urls.sql
description: Give your pages readable URLs and route requests to SQL files.
- sort_order: 6
title: Reverse proxy
link: /your-first-sql-website/nginx.sql
description: Serve your site with Nginx and HTTPS.
- sort_order: 7
title: Managed hosting
link: /your-first-sql-website/hosted.sql
description: Try SQLPage online or publish your website with DataPage.
69 changes: 69 additions & 0 deletions examples/official-site/sqlpage/content/projects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
entries:
- title: Advanced Authentication
folder: user-authentication
db_engine: postgres
description: Build a secure user authentication system with login, signup, and in-database session management.
- title: Authenticated CRUD
folder: CRUD - Authentication
db_engine: sqlite
description: Complete Create-Read-Update-Delete operations with user authentication.
- title: Image Gallery
folder: image gallery with user uploads
db_engine: sqlite
description: Create an image gallery with user uploads and session management.
- title: Developer UI
folder: SQLPage developer user interface
db_engine: postgres
description: A web-based interface for managing SQLPage files and database tables.
- title: Corporate Game
folder: corporate-conundrum
db_engine: sqlite
description: An interactive multiplayer board game with real-time updates.
- title: Roundest Pokemon
folder: roundest_pokemon_rating
db_engine: sqlite
description: Demo app with a distinct non-default design, using custom HTML templates for everything.
- title: Todo Application
folder: todo application (PostgreSQL)
db_engine: postgres
description: A full-featured todo list application with PostgreSQL backend.
- title: MySQL & JSON
folder: mysql json handling
db_engine: mysql
description: Learn advanced JSON manipulation in MySQL to build advanced SQLPage applications.
- title: Apache Web Server
folder: web servers - apache
db_engine: mysql
description: Use an existing Apache httpd Web Server to expose your SQLPage application.
- title: Sending Emails
folder: sending emails
db_engine: sqlite
description: Send email and attachments through SMTP with sqlpage.send_mail, and inspect the messages in a local Mailpit inbox.
- title: Simple Website
folder: simple-website-example
db_engine: sqlite
description: Basic website example with navigation and data management.
- title: Geographic App
folder: PostGIS - using sqlpage with geographic data
db_engine: postgres
description: Use SQLPage to create and manage geodata.
- title: Multi-step form
folder: forms-with-multiple-steps
db_engine: sqlite
description: Guide to the implementation of forms that spread over multiple pages.
- title: Custom HTML & JS
folder: custom form component
db_engine: mysql
description: Building a custom form component with a dynamic widget using HTML and javascript.
- title: Splitwise Clone
folder: splitwise
db_engine: sqlite
description: An expense tracker app to split expenses with your friends, with nice debt charts.
- title: Advanced Forms with MS SQL Server
folder: microsoft sql server advanced forms
db_engine: sql server
description: Forms with multi-value dropdowns, using SQL Server and its JSON functions.
- title: Rich Text Editor
folder: rich-text-editor
db_engine: sqlite
description: A rich text editor with bold, italic, lists, images, and more. It posts its contents as Markdown.
110 changes: 6 additions & 104 deletions examples/official-site/sqlpage/migrations/62_example_cards.sql
Original file line number Diff line number Diff line change
@@ -1,104 +1,6 @@
create table
example_cards as
select
'Advanced Authentication' as title,
'user-authentication' as folder, -- Has to exactly match the folder name in the /examples/ directory
'postgres' as db_engine,
'Build a secure user authentication system with login, signup, and in-database session management.' as description
union all
select
'Authenticated CRUD',
'CRUD - Authentication',
'sqlite',
'Complete Create-Read-Update-Delete operations with user authentication.'
union all
select
'Image Gallery',
'image gallery with user uploads',
'sqlite',
'Create an image gallery with user uploads and session management.'
union all
select
'Developer UI',
'SQLPage developer user interface',
'postgres',
'A web-based interface for managing SQLPage files and database tables.'
union all
select
'Corporate Game',
'corporate-conundrum',
'sqlite',
'An interactive multiplayer board game with real-time updates.'
union all
select
'Roundest Pokemon',
'roundest_pokemon_rating',
'sqlite',
'Demo app with a distinct non-default design, using custom HTML templates for everything.'
union all
select
'Todo Application',
'todo application (PostgreSQL)',
'postgres',
'A full-featured todo list application with PostgreSQL backend.'
union all
select
'MySQL & JSON',
'mysql json handling',
'mysql',
'Learn advanced JSON manipulation in MySQL to build advanced SQLPage applications.'
union all
select
'Apache Web Server',
'web servers - apache',
'mysql',
'Use an existing Apache httpd Web Server to expose your SQLPage application.'
union all
select
'Sending Emails',
'sending emails',
'sqlite',
'Send email and attachments through SMTP with sqlpage.send_mail, and inspect the messages in a local Mailpit inbox.'
union all
select
'Simple Website',
'simple-website-example',
'sqlite',
'Basic website example with navigation and data management.'
union all
select
'Geographic App',
'PostGIS - using sqlpage with geographic data',
'postgres',
'Use SQLPage to create and manage geodata.'
union all
select
'Multi-step form',
'forms-with-multiple-steps',
'sqlite',
'Guide to the implementation of forms that spread over multiple pages.'
union all
select
'Custom HTML & JS',
'custom form component',
'mysql',
'Building a custom form component with a dynamic widget using HTML and javascript.'
union all
select
'Splitwise Clone',
'splitwise',
'sqlite',
'An expense tracker app to split expenses with your friends, with nice debt charts.'
union all
select
'Advanced Forms with MS SQL Server',
'microsoft sql server advanced forms',
'sql server',
'Forms with multi-value dropdowns, using SQL Server and its JSON functions.'
union all
select
'Rich Text Editor',
'rich-text-editor',
'sqlite',
'A rich text editor with bold, italic, lists, images, and more. It posts its contents as Markdown.'
;
CREATE TABLE example_cards (
title TEXT NOT NULL,
folder TEXT NOT NULL UNIQUE,
db_engine TEXT,
description TEXT NOT NULL
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,3 @@ CREATE TABLE guide (
link TEXT NOT NULL UNIQUE,
description TEXT NOT NULL
);

INSERT INTO guide (sort_order, title, link, description) VALUES
(1, 'Your first website', '/your-first-sql-website/', 'Install SQLPage and build a website from a SQL file.'),
(2, 'SQL and variables', '/extensions-to-sql.sql', 'Read request parameters, set variables, and call SQLPage functions.'),
(3, 'Custom components', '/custom_components.sql', 'Render your own HTML with Handlebars templates.'),
(4, 'Database migrations', '/your-first-sql-website/migrations.sql', 'Create and update your database schema with versioned SQL files.'),
(5, 'Custom URLs', '/your-first-sql-website/custom_urls.sql', 'Give your pages readable URLs and route requests to SQL files.'),
(6, 'Reverse proxy', '/your-first-sql-website/nginx.sql', 'Serve your site with Nginx and HTTPS.'),
(7, 'Managed hosting', '/your-first-sql-website/hosted.sql', 'Try SQLPage online or publish your website with DataPage.');
74 changes: 74 additions & 0 deletions scripts/official-site/directories.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use anyhow::{Context, Result, ensure};
use config::{Config, File, FileFormat};
use serde::{Deserialize, de::DeserializeOwned};
use sqlx::{query::query, sqlite::SqliteConnection};
use std::{collections::HashSet, fs, path::Path};

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Guide {
title: String,
link: String,
description: String,
sort_order: i64,
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Project {
title: String,
folder: String,
db_engine: Option<String>,
description: String,
}

pub(super) async fn insert(db: &mut SqliteConnection, site: &Path, examples: &Path) -> Result<()> {
let content = site.join("sqlpage/content");
for guide in entries::<Guide>(&content.join("guides.yaml"))? {
query("INSERT INTO guide (title, link, description, sort_order) VALUES (?, ?, ?, ?)")
.bind(guide.title)
.bind(&guide.link)
.bind(guide.description)
.bind(guide.sort_order)
.execute(&mut *db)
.await
.with_context(|| format!("Storing guide {}", guide.link))?;
}

let mut folders = HashSet::new();
for entry in fs::read_dir(examples)? {
let entry = entry?;
if entry.file_type()?.is_dir() {
folders.insert(entry.file_name());
}
}
for project in entries::<Project>(&content.join("projects.yaml"))? {
ensure!(
folders.contains(std::ffi::OsStr::new(&project.folder)),
"Example project {:?} does not match a directory in {}",
project.folder,
examples.display()
);
query(
"INSERT INTO example_cards (title, folder, db_engine, description) VALUES (?, ?, ?, ?)",
)
.bind(project.title)
.bind(&project.folder)
.bind(project.db_engine)
.bind(project.description)
.execute(&mut *db)
.await
.with_context(|| format!("Storing example project {}", project.folder))?;
}
Ok(())
}

fn entries<T: DeserializeOwned>(path: &Path) -> Result<Vec<T>> {
let text = super::read(path)?;
Config::builder()
.add_source(File::from_str(&text, FileFormat::Yaml))
.build()
.with_context(|| path.display().to_string())?
.get("entries")
.with_context(|| path.display().to_string())
}
3 changes: 3 additions & 0 deletions scripts/official-site/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async fn main() -> Result<()> {
}
}
let example_count = stage_site(&site, &output, &mut tx).await?;
directories::insert(&mut tx, &site, &root.join("examples")).await?;
// Publish the exact sample schema and rows used by the copyable reference queries.
let migrations = site.join("sqlpage/migrations");
let sample_data = [
Expand Down Expand Up @@ -101,6 +102,8 @@ fn builds_official_site() -> Result<()> {
main()
}

mod directories;

async fn stage_site(source: &Path, output: &Path, db: &mut SqliteConnection) -> Result<usize> {
let mut example_count = 0;
let excluded = [
Expand Down
Loading