You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -137,13 +137,16 @@ An alternative for Mac OS users is to use [SQLPage's homebrew package](https://f
137
137
138
138
## Examples
139
139
140
+
-[Plots, Tables, forms, and interactivity](./examples/plots%20tables%20and%20forms/): a short well-commented demo showing how to use plots, tables, forms, and interactivity to filter data based on an URL parameter.
140
141
-[Tiny splitwise clone](./examples/splitwise): a shared expense tracker app
141
142
-[Corporate Conundrum](./examples/corporate-conundrum/): a board game implemented in SQL
142
143
-[Master-Detail Forms](./examples/master-detail-forms/): shows how to implement a simple set of forms to insert data into database tables that have a one-to-many relationship.
143
144
-[SQLPage's own official website and documentation](./examples/official-site/): The SQL source code for the project's official site, https://sql.ophir.dev
144
145
-[User Management](./examples/user-authentication/): An authentication demo with user registration, log in, log out, and confidential pages. Uses PostgreSQL.
145
146
-[Making a JSON API and integrating React components in the frontend](./examples/using%20react%20and%20other%20custom%20scripts%20and%20styles/): Shows how to integrate a react component in a SQLPage website, and how to easily build a REST API with SQLPage.
146
147
148
+
You can try all the examples online using [SQLPage's online demo on replit](https://replit.com/@pimaj62145/SQLPage).
149
+
147
150
## Configuration
148
151
149
152
SQLPage can be configured through either a configuration file placed in `sqlpage/sqlpage.json`
-- Welcome to SQLPage ! This is a short demonstration of a few things you can do with SQLPage
2
+
-- Using the 'shell' component at the top allows you to customize your web page, giving it a title and a description
3
+
select'shell'as component,
4
+
'SQLpage'as title,
5
+
'/'as link,
6
+
'en'as lang,
7
+
'SQLPage Demo'as description;
8
+
9
+
-- Making a web page with SQLPage works by using a set of predefined "components"
10
+
-- and filling them with contents from the results of your SQL queries
11
+
select'hero'as component, -- We select a component. The documentation for each component can be found on https://sql.ophir.dev/documentation.sql
12
+
'It works !'as title, -- 'title' is top-level parameter of the 'hero' component
13
+
'If you can see this, then SQLPage is running correctly on your server. Congratulations! 'as description;
14
+
-- Properties can be textual, numeric, or booleans
15
+
16
+
-- Let's start with the text component
17
+
SELECT'text'as component, -- We can switch to another component at any time just with a select statement.
18
+
'Get started'as title;
19
+
-- We are now inside the text component. Each row that will be returned by our SELECT queries will be a span of text
20
+
-- The text component has a property called "contents" that can be that we use to set the contents of our block of text
21
+
-- and a property called "center" that we use to center the text
22
+
SELECT'In order to get started 'as contents;
23
+
select'visit SQLPage''s website'as contents,
24
+
'https://sql.ophir.dev/'as link,
25
+
true as italics;
26
+
SELECT'. You can replace this page''s contents by creating a file named 'as contents;
27
+
SELECT'index.sql'as contents, true as italics;
28
+
SELECT' in the folder where sqlpage is running. 'as contents;
29
+
SELECT'Alternatively, you can create a table called sqlpage_files in your database with the following columns: path, contents, and last_modified.'as contents;
30
+
31
+
-- The text component also support rich text using the markdown syntax with the property "contents_md"
32
+
SELECT'
33
+
## Rich text
34
+
You can use markdown syntax in SQLPage to make your text **bold**, *italic*, or even [add links](https://sql.ophir.dev/).
35
+
'as contents_md;
36
+
37
+
select'text'as component,
38
+
'Demo'as title;
39
+
-- We can switch to another component at any time just with a select statement.
40
+
-- Let's draw a chart
41
+
select'chart'as component, -- selecting a different component
42
+
'Revenue per country'as title, -- setting the component's top-level properties. The documentation for each component's properties can be found on https://sql.ophir.dev/documentation.sql
43
+
'bar'as type,
44
+
'time'as xtitle,
45
+
'price'as ytitle,
46
+
true as stacked;
47
+
-- Inside the chart component, we have access to the "series", "label", and "value" row-level properties
48
+
-- Here, we are selecting static data, but you can also use a query to a real database
49
+
select'Russia'as series,
50
+
'2022-01'as label,
51
+
2as value
52
+
union
53
+
select'Russia',
54
+
'2022-02',
55
+
4
56
+
union
57
+
select'Russia',
58
+
'2022-03',
59
+
2;
60
+
select'Brasil'as series,
61
+
'2022-01'as label,
62
+
4as value
63
+
union
64
+
select'Brasil',
65
+
'2022-03',
66
+
1
67
+
union
68
+
select'Brasil',
69
+
'2022-04',
70
+
1;
71
+
-- Let's make a new chart, this time generating the data with a more complex query
a.x||' x '||b.x||' = '|| (a.x*b.x) as description,
109
+
'This is basic math'as footer,
110
+
'?x='||a.xas link -- This is the interesting part. Each card has a link. When you click the card, the current page is reloaded with '?x=a' appended to the end of the URL
111
+
FROM nums as a, nums as b
112
+
WHERE-- The powerful thing is here
113
+
$x IS NULL
114
+
OR-- The syntax $x allows us to extract the value 'a' when the URL ends with '?x=a'. It will be null if the URL does not contain '?x='
115
+
b.x= $x::DECIMAL
116
+
ORDER BYa.x, b.x;
117
+
-- So when we click the card for "a times b", we will reload the page, and display only the multiplication table of a
118
+
---------------------------
119
+
-- FORMS --
120
+
-- Until now, we have only read data. Let's see how we can write new data to our database
121
+
-- You can use an existing table in your database
122
+
-- or create the table by just creating a file at 'sqlpage/migrations/00_create_users.sql'
123
+
-- containing the SQL query to create the table. For this example, we will use:
124
+
-- CREATE TABLE IF NOT EXISTS users(name TEXT);
125
+
126
+
-- Displaying a form is as easy as displaying a table; we use the "form" component
127
+
-- Let's display a form to our users
128
+
select'form'as component,
129
+
'Create'as validate,
130
+
'New User'as title;
131
+
select'number'as type,
132
+
'age'as placeholder;
133
+
select'First Name'as name,
134
+
true as autocomplete,
135
+
true as required,
136
+
'We need your name for legal reasons.'as description;
137
+
select'Last name'as name,
138
+
true as autocomplete;
139
+
select'radio'as type,
140
+
'favorite_food'as name,
141
+
'banana'as value,
142
+
'I like bananas the most'as label;
143
+
select'radio'as type,
144
+
'favorite_food'as name,
145
+
'cake'as value,
146
+
'I like cake more'as label,
147
+
'Bananas are okay, but I prefer cake'as description;
148
+
select'checkbox'as type,
149
+
'checks[]'as name,
150
+
1as value,
151
+
'Accept the terms and conditions'as label;
152
+
select'checkbox'as type,
153
+
'checks[]'as name,
154
+
2as value,
155
+
'Subscribe to the newsletter'as label;
156
+
157
+
-- We can access the values entered in the form using the syntax :xxx where 'xxx' is the name of one of the fields in the form
158
+
-- insert into users select :"First Name" where :"First Name" IS NOT NULL;
159
+
-- We don't want to add a line in the database if the page was loaded without entering a value in the form, so we add a WHERE clause
160
+
-- Let's show the users we have in our database
161
+
-- select 'list' as component, 'Users' as title;
162
+
-- select name as title from users;
163
+
-- The debug component displays the raw results returned by a query
SELECT'. You can replace this page''s contents by creating a file named 'as contents;
26
26
SELECT'index.sql'as contents, true as italics;
27
27
SELECT' in the folder where sqlpage is running. 'as contents;
28
28
SELECT'Alternatively, you can create a table called sqlpage_files in your database with the following columns: path, contents, and last_modified.'as contents;
29
-
30
-
select'text'as component,
31
-
'Demo'as title;
32
-
-- We can switch to another component at any time just with a select statement.
33
-
-- Let's draw a chart
34
-
select'chart'as component,
35
-
'Revenue per country'as title,
36
-
'bar'as type,
37
-
'time'as xtitle,
38
-
'price'as ytitle,
39
-
true as stacked;
40
-
-- Inside the chart component, we have access to the "series", "label", and "value" properties
41
-
-- Here, we are selecting static data, but you can also use a query to a real database
42
-
select'Russia'as series,
43
-
'2022-01'as label,
44
-
2as value
45
-
union
46
-
select'Russia',
47
-
'2022-02',
48
-
4
49
-
union
50
-
select'Russia',
51
-
'2022-03',
52
-
2;
53
-
select'Brasil'as series,
54
-
'2022-01'as label,
55
-
4as value
56
-
union
57
-
select'Brasil',
58
-
'2022-03',
59
-
1
60
-
union
61
-
select'Brasil',
62
-
'2022-04',
63
-
1;
64
-
-- Let's make a new chart, this time generating the data with a more complex query
a.x||' x '||b.x||' = '|| (a.x*b.x) as description,
102
-
'This is basic math'as footer,
103
-
'?x='||a.xas link -- This is the interesting part. Each card has a link. When you click the card, the current page is reloaded with '?x=a' appended to the end of the URL
104
-
FROM nums as a, nums as b
105
-
WHERE-- The powerful thing is here
106
-
$x IS NULL
107
-
OR-- The syntax $x allows us to extract the value 'a' when the URL ends with '?x=a'. It will be null if the URL does not contain '?x='
108
-
b.x= $x::DECIMAL
109
-
ORDER BYa.x, b.x;
110
-
-- So when we click the card for "a times b", we will reload the page, and display only the multiplication table of a
111
-
---------------------------
112
-
-- FORMS --
113
-
-- Until now, we have only read data. Let's see how we can write new data to our database
114
-
-- You can use an existing table in your database
115
-
-- or create the table by just creating a file at 'sqlpage/migrations/00_create_users.sql'
116
-
-- containing the SQL query to create the table. For this example, we will use:
117
-
-- CREATE TABLE IF NOT EXISTS users(name TEXT);
118
-
119
-
-- Displaying a form is as easy as displaying a table; we use the "form" component
120
-
-- Let's display a form to our users
121
-
select'form'as component,
122
-
'Create'as validate,
123
-
'New User'as title;
124
-
select'number'as type,
125
-
'age'as placeholder;
126
-
select'First Name'as name,
127
-
true as autocomplete,
128
-
true as required,
129
-
'We need your name for legal reasons.'as description;
130
-
select'Last name'as name,
131
-
true as autocomplete;
132
-
select'radio'as type,
133
-
'favorite_food'as name,
134
-
'banana'as value,
135
-
'I like bananas the most'as label;
136
-
select'radio'as type,
137
-
'favorite_food'as name,
138
-
'cake'as value,
139
-
'I like cake more'as label,
140
-
'Bananas are okay, but I prefer cake'as description;
141
-
select'checkbox'as type,
142
-
'checks[]'as name,
143
-
1as value,
144
-
'Accept the terms and conditions'as label;
145
-
select'checkbox'as type,
146
-
'checks[]'as name,
147
-
2as value,
148
-
'Subscribe to the newsletter'as label;
149
-
150
-
-- We can access the values entered in the form using the syntax :xxx where 'xxx' is the name of one of the fields in the form
151
-
-- insert into users select :"First Name" where :"First Name" IS NOT NULL;
152
-
-- We don't want to add a line in the database if the page was loaded without entering a value in the form, so we add a WHERE clause
153
-
-- Let's show the users we have in our database
154
-
-- select 'list' as component, 'Users' as title;
155
-
-- select name as title from users;
156
-
-- The debug component displays the raw results returned by a query
0 commit comments