SQLPage v0.20.4 documentation

If you are completely new to SQLPage, you should start by reading the get started tutorial, which will guide you through the process of creating your first SQLPage application.

Building an application with SQLPage is quite simple. To create a new web page, just create a new SQL file. For each SELECT statement that you write, the data it returns will be analyzed and rendered to the user. The two most important concepts in SQLPage are components and parameters.

To select a component and set its top-level properties, you write the following SQL statement:

SELECT 'component_name' AS component, 'my value' AS top_level_parameter_1;

Then, you can set its row-level parameters by writing a second SELECT statement:

SELECT my_column_1 AS row_level_parameter_1, my_column_2 AS row_level_parameter_2 FROM my_table;

This page documents all the components provided by default in SQLPage and their parameters. Use this as a reference when building your SQL application. If at any point you need help, you can ask for it on the SQLPage forum.

If you know some HTML, you can also easily create your own components for your application.

components

The "table" component

A table with optional filtering and sorting. Unlike most others, this component does not have a fixed set of item properties, any property that is used will be rendered directly as a column in the table. Tables can contain rich text, including images, links, and icons. Table rows can be styled with a background color, and the table can be made striped, hoverable, and bordered. Advanced users can apply custom styles to table columns using a CSS class with the same name as the column, and to table rows using the `_sqlpage_css_class` property.

Top-level parameters

align_right

Name of a column the contents of which should be right-aligned. This argument can be repeated multiple times to align multiple columns to the right. Introduced in v0.15.0.

border

Whether to draw borders on all sides of the table and cells.

class

class attribute added to the container in HTML. It can be used to apply custom styling to this item through css. Added in v0.18.0.

description

Description of the table content and helps users with screen readers to find a table and understand what it’s.

hover

Whether to enable a hover state on table rows.

icon

Set this to the name of a column whose content should be interpreted as a tabler icon name. Used to display icons in the table. This argument can be repeated multiple times to intepret multiple columns as icons. Introduced in v0.8.0.

id

id attribute added to the container in HTML. It can be used to target this item through css or for scrolling to this item through links (use "#id" in link url).

markdown

Set this to the name of a column whose content should be interpreted as markdown . Used to display rich text with links in the table. This argument can be repeated multiple times to intepret multiple columns as markdown.

search

Add a search bar at the top of the table, letting users easily filter table rows by value.

small

Whether to use compact table.

sort

Make the columns clickable to let the user sort by the value contained in the column.

striped_columns

Whether to add zebra-striping to any table column.

striped_rows

Whether to add zebra-striping to any table row.

Row-level parameters

_sqlpage_color

Sets the background color of the row. Added in v0.8.0.

_sqlpage_css_class

For advanced users. Sets a css class on the table row. Added in v0.8.0.

Example 1

The most basic table.

select 
    'table' as component;
select 
    1 as a,
    2 as b;
select 
    3 as a,
    4 as b;

Result

a b
12
34

Example 2

A table of users with filtering and sorting.

select 
    'table' as component,
    TRUE    as sort,
    TRUE    as search;
select 
    'Ophir'   as Forename,
    'Lojkine' as Surname,
    'lovasoa' as Pseudonym;
select 
    'Linus'    as Forename,
    'Torvalds' as Surname,
    'torvalds' as Pseudonym;

Result

OphirLojkinelovasoa
LinusTorvaldstorvalds

Example 3

A table that uses markdown to display links

select 
    'table'         as component,
    'Documentation' as markdown,
    'icon'          as icon,
    TRUE            as sort,
    TRUE            as search;
select 
    'table' as icon,
    'Table' as name,
    'Displays SQL results as a searchable table.' as description,
    '[docs](documentation.sql?component=table)' as Documentation,
    'red'   as _sqlpage_color;
select 
    'timeline' as icon,
    'Chart'    as name,
    'Show graphs based on numeric data.' as description,
    '[docs](documentation.sql?component=chart)' as Documentation;

Result

TableDisplays SQL results as a searchable table.

docs

ChartShow graphs based on numeric data.

docs

Example 4

A table with numbers

select 
    'table'           as component,
    TRUE              as search,
    TRUE              as sort,
    'Price ($)'       as align_right,
    'Amount in stock' as align_right;
select 
    31456                 as id,
    'MIC-ROCC-F-23-206-C' as part_no,
    12                    as "Price ($)",
    5                     as "Amount in stock";
select 
    996                   as id,
    'MIC-ROCC-F-24-206-A' as part_no,
    1                     as "Price ($)",
    15                    as "Amount in stock";
select 
    131456                as id,
    'KIB-ROCC-F-13-205-B' as part_no,
    127                   as "Price ($)",
    9                     as "Amount in stock";

Result

31456MIC-ROCC-F-23-206-C125
996MIC-ROCC-F-24-206-A115
131456KIB-ROCC-F-13-205-B1279

Example 5

A table with some presentation options

select 
    'table' as component,
    TRUE    as hover,
    TRUE    as striped_rows,
    'Some Star Trek Starfleet starships' as description,
    TRUE    as small;
select 
    'USS Enterprise' as name,
    'NCC-1701-C'     as registry,
    'Ambassador'     as class;
select 
    'USS Archer' as name,
    'NCC-44278'  as registry,
    'Archer'     as class;
select 
    'USS Endeavour' as name,
    'NCC-06'        as registry,
    'Columbia'      as class;
select 
    'USS Constellation' as name,
    'NCC-1974'          as registry,
    'Constellation'     as class;
select 
    'USS Dakota' as name,
    'NCC-63892'  as registry,
    'Akira'      as class;

Result

Some Star Trek Starfleet starships
name registry class
USS EnterpriseNCC-1701-CAmbassador
USS ArcherNCC-44278Archer
USS EndeavourNCC-06Columbia
USS ConstellationNCC-1974Constellation
USS DakotaNCC-63892Akira

Official SQLPage documentation