Understanding SQLPage’s component-based UI rendering system
SQLPage uses a component-based rendering system that transforms SQL query results into interactive user interfaces. Each component is a reusable UI element configured through SQL SELECT statements.
Components are the building blocks of SQLPage pages. You select a component and configure it using SQL:
-- Select a componentSELECT 'card' as component, 'My Dashboard' as title;-- Add items to the componentSELECT 'Total Users' as title, user_count as value, 'users' as iconFROM statistics;
The column named component tells SQLPage which UI component to render. All other columns configure that component’s appearance and behavior.
-- Component initializationSELECT 'card' as component, 3 as columns;-- ItemsSELECT 'Product Sales' as title, '$' || sales_total as value, 'green' as colorFROM metrics WHERE metric = 'sales';SELECT 'Active Users' as title, user_count as value, 'blue' as colorFROM metrics WHERE metric = 'users';SELECT 'Page Views' as title, views as value, 'orange' as colorFROM metrics WHERE metric = 'views';
SELECT 'table' as component, TRUE as sort, TRUE as search;SELECT name as "Name", email as "Email", created_at as "Joined"FROM usersORDER BY created_at DESC;
Features:
Sortable columns
Search filtering
Pagination
Responsive design
list - Item Lists
SELECT 'list' as component, 'Tasks' as title;SELECT task_name as title, description, 'edit.sql?id=' || id as linkFROM tasks;
Displays items with:
Title and description
Icons or images
Action links
card - Grid of Cards
SELECT 'card' as component, 3 as columns;SELECT title, description, image_url as top_image, linkFROM products;
Responsive grid layout:
1-6 columns
Images and text
Clickable cards
chart - Data Visualization
SELECT 'chart' as component, 'Revenue Trends' as title, 'bar' as type;SELECT month as label, revenue as value, 'Revenue' as seriesFROM monthly_stats;
SELECT 'form' as component, 'user_update' as id, 'Update User' as title, 'Save Changes' as validate;-- Text inputSELECT 'text' as type, 'username' as name, 'Username' as label, $current_username as value, TRUE as required;-- Email inputSELECT 'email' as type, 'email' as name, 'Email Address' as label;-- Select dropdownSELECT 'select' as type, 'role' as name, 'User Role' as label;SELECT role_id as value, role_name as labelFROM roles;
Accessing form data:
-- POST parameters use :name syntaxUPDATE usersSET username = :username, email = :email, role = :roleWHERE id = $user_id;
Switch between components by selecting a new component:
-- Component 1: HeroSELECT 'hero' as component, 'Dashboard' as title;-- Component 2: CardsSELECT 'card' as component, 3 as columns;SELECT 'Sales' as title, sales as value FROM metrics;-- Component 3: TableSELECT 'table' as component, 'Recent Orders' as title;SELECT * FROM orders LIMIT 10;-- Component 4: ChartSELECT 'chart' as component, 'Trends' as title, 'line' as type;SELECT date as label, revenue as value FROM daily_stats;
Each new SELECT ... as component statement closes the previous component and starts a new one.
SELECT 'card' as component;SELECT product_name as title, description, price as value, category as footer, image_url as top_image, '/product?id=' || product_id as linkFROM productsWHERE featured = TRUE;