Skip to content

Commit 8c38c6d

Browse files
committed
newfunction: sqlpage.version
1 parent f430685 commit 8c38c6d

File tree

8 files changed

+26
-8
lines changed

8 files changed

+26
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
You can write your code in .sql files in /path/to/your/website/directory.
1313
```
1414
- New `sqlpage.current_working_directory` function to get the [current working directory](https://en.wikipedia.org/wiki/Working_directory) of the SQLPage process.
15+
- New `sqlpage.version` function to get the version of SQLPage.
1516
1617
## 0.10.3 (2023-09-14)
1718

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlpage"
3-
version = "0.10.4"
3+
version = "0.11.0"
44
edition = "2021"
55
description = "A SQL-only web application framework. Takes .sql files and formats the query result using pre-made configurable professional-looking components."
66
keywords = ["web", "sql", "framework"]

examples/official-site/documentation.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control";
33
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
44

5-
select 'text' as component, 'SQLPage documentation' as title;
5+
select 'text' as component, format('SQLPage v%s documentation', sqlpage.version()) as title;
66
select '
77
If you are completely new to SQLPage, you should start by reading the [get started tutorial](get%20started.sql),
88
which will guide you through the process of creating your first SQLPage application.
@@ -53,7 +53,8 @@ select 'text' as component,
5353
select description as contents from component where name = $component;
5454

5555
select 'text' as component;
56-
select 'Introduced in SQLPage v' || introduced_in_version || '.' as contents, 1 as size
56+
select format('Introduced in SQLPage v%s.', introduced_in_version) as contents,
57+
1 as size
5758
from component where name = $component;
5859

5960
select 'title' as component, 3 as level, 'Top-level parameters' as contents where $component IS NOT NULL;

examples/official-site/sqlpage/migrations/08_functions.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,16 @@ VALUES (
270270
'name',
271271
'The name of the environment variable to read. Must be a literal string.',
272272
'TEXT'
273-
);
273+
);
274+
275+
INSERT INTO sqlpage_functions (
276+
"name",
277+
"introduced_in_version",
278+
"icon",
279+
"description_md"
280+
)
281+
VALUES (
282+
'version',
283+
'0.11.0',
284+
'git-commit',
285+
'Returns the current version of SQLPage as a string.');

index.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ select 'shell' as component,
99
-- and filling them with contents from the results of your SQL queries
1010
select 'hero' as component, -- We select a component. The documentation for each component can be found on https://sql.ophir.dev/documentation.sql
1111
'It works !' as title, -- 'title' is top-level parameter of the 'hero' component
12-
'If you can see this, then SQLPage is running correctly on your server. Congratulations! ' as description;
12+
'If you can see this, then SQLPage v' ||
13+
sqlpage.version() ||
14+
' is running correctly on your server. Congratulations! ' as description;
1315
-- Properties can be textual, numeric, or booleans
1416

1517
-- Let's start with the text component

src/webserver/database/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ fn bind_parameters<'a>(
182182
) -> anyhow::Result<Query<'a, sqlx::Any, AnyArguments<'a>>> {
183183
let mut arguments = AnyArguments::default();
184184
for param in &stmt.parameters {
185-
let argument = extract_req_param(param, request)
186-
.with_context(|| format!("Unable to extract {param:?} from the HTTP request"))?;
185+
let argument = extract_req_param(param, request)?;
187186
log::debug!("Binding value {:?} in statement {}", &argument, stmt);
188187
match argument {
189188
None => arguments.add(None::<String>),

src/webserver/database/sql_pseudofunctions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub(super) enum StmtParam {
2828
RandomString(usize),
2929
CurrentWorkingDir,
3030
EnvironmentVariable(String),
31+
SqlPageVersion,
3132
}
3233

3334
pub(super) fn func_call_to_param(func_name: &str, arguments: &mut [FunctionArg]) -> StmtParam {
@@ -46,6 +47,7 @@ pub(super) fn func_call_to_param(func_name: &str, arguments: &mut [FunctionArg])
4647
"current_working_directory" => StmtParam::CurrentWorkingDir,
4748
"environment_variable" => extract_single_quoted_string("environment_variable", arguments)
4849
.map_or_else(StmtParam::Error, StmtParam::EnvironmentVariable),
50+
"version" => StmtParam::SqlPageVersion,
4951
unknown_name => StmtParam::Error(format!(
5052
"Unknown function {unknown_name}({})",
5153
FormatArguments(arguments)
@@ -82,6 +84,7 @@ pub(super) fn extract_req_param<'a>(
8284
.map(Cow::Owned)
8385
.map(Some)
8486
.with_context(|| format!("Unable to read environment variable {var}"))?,
87+
StmtParam::SqlPageVersion => Some(Cow::Borrowed(env!("CARGO_PKG_VERSION"))),
8588
})
8689
}
8790

0 commit comments

Comments
 (0)