Skip to content

Commit 1af44a7

Browse files
committed
fmt
1 parent 85656c4 commit 1af44a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+369
-251
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG.md
22

3-
## unreleased
3+
## v0.44.0
44

55
- New function: `sqlpage.regex_match(pattern, text)`. Useful for easy routing using `sqlpage.path()` from 404.sql files.
66
- Added a `show_legend` top level property to the chart component.

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "sqlpage"
3-
version = "0.43.0"
4-
edition = "2021"
3+
version = "0.44.0"
4+
edition = "2024"
55
description = "Build data user interfaces entirely in SQL. A web server that takes .sql files and formats the query result using pre-made configurable professional-looking components."
66
keywords = ["web", "sql", "framework"]
77
license = "MIT"

src/app_config.rs

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cli::arguments::{parse_cli, Cli};
1+
use crate::cli::arguments::{Cli, parse_cli};
22
use crate::webserver::content_security_policy::ContentSecurityPolicyTemplate;
33
use crate::webserver::routing::RoutingConfig;
44
use actix_web::http::Uri;
@@ -351,13 +351,8 @@ pub struct AppConfig {
351351
impl AppConfig {
352352
#[must_use]
353353
pub fn cache_stale_duration_ms(&self) -> u64 {
354-
self.cache_stale_duration_ms.unwrap_or_else(|| {
355-
if self.environment.is_prod() {
356-
1000
357-
} else {
358-
0
359-
}
360-
})
354+
self.cache_stale_duration_ms
355+
.unwrap_or_else(|| if self.environment.is_prod() { 1000 } else { 0 })
361356
}
362357

363358
#[must_use]
@@ -458,7 +453,9 @@ where
458453
Some(PortOrUrl::Port(p)) => Ok(Some(p)),
459454
Some(PortOrUrl::Url(u)) => {
460455
if let Ok(u) = Uri::from_str(&u) {
461-
log::warn!("{u} is not a valid value for the SQLPage port number. Ignoring this error since kubernetes may set the SQLPAGE_PORT env variable to a service URI when there is a service named sqlpage. Rename your service to avoid this warning.");
456+
log::warn!(
457+
"{u} is not a valid value for the SQLPage port number. Ignoring this error since kubernetes may set the SQLPAGE_PORT env variable to a service URI when there is a service named sqlpage. Rename your service to avoid this warning."
458+
);
462459
Ok(None)
463460
} else {
464461
Err(D::Error::custom(format!(
@@ -561,7 +558,11 @@ fn create_default_database(configuration_directory: &Path) -> String {
561558
let old_default_db_path = PathBuf::from(DEFAULT_DATABASE_FILE);
562559
let default_db_path = config_dir.join(DEFAULT_DATABASE_FILE);
563560
if let Ok(true) = old_default_db_path.try_exists() {
564-
log::warn!("Your sqlite database in {} is publicly accessible through your web server. Please move it to {}.", old_default_db_path.display(), default_db_path.display());
561+
log::warn!(
562+
"Your sqlite database in {} is publicly accessible through your web server. Please move it to {}.",
563+
old_default_db_path.display(),
564+
default_db_path.display()
565+
);
565566
return prefix + old_default_db_path.to_str().unwrap();
566567
} else if let Ok(true) = default_db_path.try_exists() {
567568
log::debug!(
@@ -578,13 +579,18 @@ fn create_default_database(configuration_directory: &Path) -> String {
578579
);
579580
drop(tmp_file);
580581
if let Err(e) = std::fs::remove_file(&default_db_path) {
581-
log::debug!("Unable to remove temporary probe file. It might have already been removed by another instance started concurrently: {e}");
582+
log::debug!(
583+
"Unable to remove temporary probe file. It might have already been removed by another instance started concurrently: {e}"
584+
);
582585
}
583586
return prefix + &encode_uri(&default_db_path) + "?mode=rwc";
584587
}
585588
}
586589

587-
log::warn!("No DATABASE_URL provided, and {} is not writeable. Using a temporary in-memory SQLite database. All the data created will be lost when this server shuts down.", configuration_directory.display());
590+
log::warn!(
591+
"No DATABASE_URL provided, and {} is not writeable. Using a temporary in-memory SQLite database. All the data created will be lost when this server shuts down.",
592+
configuration_directory.display()
593+
);
588594
prefix + ":memory:?cache=shared"
589595
}
590596

@@ -707,8 +713,8 @@ pub fn test_database_url() -> String {
707713

708714
#[cfg(test)]
709715
pub mod tests {
710-
pub use super::test_database_url;
711716
use super::AppConfig;
717+
pub use super::test_database_url;
712718

713719
#[must_use]
714720
pub fn test_config() -> AppConfig {
@@ -762,9 +768,7 @@ mod test {
762768
assert_eq!(normalize_site_prefix("a b/c"), "/a%20b/c/");
763769
assert_eq!(normalize_site_prefix("*-+/:;,?%\"'{"), "/*-+/:;,%3F%%22'{/");
764770
assert_eq!(
765-
normalize_site_prefix(
766-
&(0..=0x7F).map(char::from).collect::<String>()
767-
),
771+
normalize_site_prefix(&(0..=0x7F).map(char::from).collect::<String>()),
768772
"/%00%01%02%03%04%05%06%07%08%0B%0C%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%&'()*+,-./0123456789:;%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~%7F/"
769773
);
770774
}
@@ -774,7 +778,9 @@ mod test {
774778
let _lock = ENV_LOCK
775779
.lock()
776780
.expect("Another test panicked while holding the lock");
777-
unsafe { env::set_var("SQLPAGE_CONFIGURATION_DIRECTORY", "/path/to/config"); }
781+
unsafe {
782+
env::set_var("SQLPAGE_CONFIGURATION_DIRECTORY", "/path/to/config");
783+
}
778784

779785
let config = load_from_env().unwrap();
780786

@@ -784,41 +790,53 @@ mod test {
784790
"Configuration directory should match the SQLPAGE_CONFIGURATION_DIRECTORY env var"
785791
);
786792

787-
unsafe { env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY"); }
793+
unsafe {
794+
env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY");
795+
}
788796
}
789797

790798
#[test]
791799
fn test_k8s_env_var_ignored() {
792800
let _lock = ENV_LOCK
793801
.lock()
794802
.expect("Another test panicked while holding the lock");
795-
unsafe { env::set_var("SQLPAGE_PORT", "tcp://10.0.0.1:8080"); }
803+
unsafe {
804+
env::set_var("SQLPAGE_PORT", "tcp://10.0.0.1:8080");
805+
}
796806

797807
let config = load_from_env().unwrap();
798808
assert_eq!(config.port, None);
799809

800-
unsafe { env::remove_var("SQLPAGE_PORT"); }
810+
unsafe {
811+
env::remove_var("SQLPAGE_PORT");
812+
}
801813
}
802814

803815
#[test]
804816
fn test_valid_port_env_var() {
805817
let _lock = ENV_LOCK
806818
.lock()
807819
.expect("Another test panicked while holding the lock");
808-
unsafe { env::set_var("SQLPAGE_PORT", "9000"); }
820+
unsafe {
821+
env::set_var("SQLPAGE_PORT", "9000");
822+
}
809823

810824
let config = load_from_env().unwrap();
811825
assert_eq!(config.port, Some(9000));
812826

813-
unsafe { env::remove_var("SQLPAGE_PORT"); }
827+
unsafe {
828+
env::remove_var("SQLPAGE_PORT");
829+
}
814830
}
815831

816832
#[test]
817833
fn test_config_priority() {
818834
let _lock = ENV_LOCK
819835
.lock()
820836
.expect("Another test panicked while holding the lock");
821-
unsafe { env::set_var("SQLPAGE_WEB_ROOT", "/"); }
837+
unsafe {
838+
env::set_var("SQLPAGE_WEB_ROOT", "/");
839+
}
822840

823841
let cli = Cli {
824842
web_root: Some(PathBuf::from(".")),
@@ -835,7 +853,9 @@ mod test {
835853
"CLI argument should take precedence over environment variable"
836854
);
837855

838-
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
856+
unsafe {
857+
env::remove_var("SQLPAGE_WEB_ROOT");
858+
}
839859
}
840860

841861
#[test]
@@ -859,7 +879,9 @@ mod test {
859879
.to_string();
860880
std::fs::write(&config_file_path, config_content).unwrap();
861881

862-
unsafe { env::set_var("SQLPAGE_WEB_ROOT", env_web_dir.to_str().unwrap()); }
882+
unsafe {
883+
env::set_var("SQLPAGE_WEB_ROOT", env_web_dir.to_str().unwrap());
884+
}
863885

864886
let cli = Cli {
865887
web_root: None,
@@ -898,7 +920,9 @@ mod test {
898920
"Configuration directory should remain unchanged"
899921
);
900922

901-
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
923+
unsafe {
924+
env::remove_var("SQLPAGE_WEB_ROOT");
925+
}
902926
std::fs::remove_dir_all(&temp_dir).unwrap();
903927
}
904928

@@ -907,8 +931,12 @@ mod test {
907931
let _lock = ENV_LOCK
908932
.lock()
909933
.expect("Another test panicked while holding the lock");
910-
unsafe { env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY"); }
911-
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
934+
unsafe {
935+
env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY");
936+
}
937+
unsafe {
938+
env::remove_var("SQLPAGE_WEB_ROOT");
939+
}
912940

913941
let cli = Cli {
914942
web_root: None,

src/file_cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use crate::webserver::routing::FileStore;
2-
use crate::webserver::ErrorWithStatus;
31
use crate::AppState;
2+
use crate::webserver::ErrorWithStatus;
3+
use crate::webserver::routing::FileStore;
44
use actix_web::http::StatusCode;
55
use anyhow::Context;
66
use async_trait::async_trait;
77
use chrono::{DateTime, TimeZone, Utc};
88
use std::collections::HashMap;
99
use std::path::{Path, PathBuf};
10+
use std::sync::Arc;
1011
use std::sync::atomic::{
1112
AtomicU64,
1213
Ordering::{Acquire, Release},
1314
};
14-
use std::sync::Arc;
1515
use std::time::SystemTime;
1616
use tokio::sync::RwLock;
1717

src/filesystem.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::webserver::database::SupportedDatabase;
21
use crate::webserver::ErrorWithStatus;
3-
use crate::webserver::{make_placeholder, Database, StatusCodeResultExt};
2+
use crate::webserver::database::SupportedDatabase;
3+
use crate::webserver::{Database, StatusCodeResultExt, make_placeholder};
44
use crate::{AppState, TEMPLATES_DIR};
55
use anyhow::Context;
66
use chrono::{DateTime, Utc};
@@ -250,10 +250,18 @@ impl DbFsQueries {
250250
#[must_use]
251251
pub fn get_create_table_sql(dbms: SupportedDatabase) -> &'static str {
252252
match dbms {
253-
SupportedDatabase::Mssql => "CREATE TABLE sqlpage_files(path NVARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY(MAX), last_modified DATETIME2(3) NOT NULL DEFAULT CURRENT_TIMESTAMP);",
254-
SupportedDatabase::Postgres => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BYTEA, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
255-
SupportedDatabase::Snowflake => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY, last_modified TIMESTAMP_TZ DEFAULT CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()));",
256-
_ => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BLOB, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
253+
SupportedDatabase::Mssql => {
254+
"CREATE TABLE sqlpage_files(path NVARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY(MAX), last_modified DATETIME2(3) NOT NULL DEFAULT CURRENT_TIMESTAMP);"
255+
}
256+
SupportedDatabase::Postgres => {
257+
"CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BYTEA, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"
258+
}
259+
SupportedDatabase::Snowflake => {
260+
"CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY, last_modified TIMESTAMP_TZ DEFAULT CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()));"
261+
}
262+
_ => {
263+
"CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BLOB, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"
264+
}
257265
}
258266
}
259267

@@ -390,7 +398,9 @@ async fn test_sql_file_read_utf8() -> anyhow::Result<()> {
390398
// Oracle has specific issues with implicit timestamp conversions and empty strings in this test setup
391399
// so we skip it for Oracle to avoid complex workarounds in the main codebase.
392400
if config.database_url.contains("Oracle") {
393-
log::warn!("Skipping test_sql_file_read_utf8 for Oracle due to date format/implicit conversion issues");
401+
log::warn!(
402+
"Skipping test_sql_file_read_utf8 for Oracle due to date format/implicit conversion issues"
403+
);
394404
return Ok(());
395405
}
396406

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use sqlpage::{
2+
AppState,
23
app_config::AppConfig,
34
cli, telemetry,
45
webserver::{self, Database},
5-
AppState,
66
};
77

88
#[actix_web::main]

src/render.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@
4141
//! For more details on available components and their usage, see the
4242
//! [SQLPage documentation](https://sql-page.com/documentation.sql).
4343
44+
use crate::AppState;
4445
use crate::templates::SplitTemplate;
46+
use crate::webserver::ErrorWithStatus;
4547
use crate::webserver::http::{RequestContext, ResponseFormat};
4648
use crate::webserver::response_writer::{AsyncResponseWriter, ResponseWriter};
47-
use crate::webserver::ErrorWithStatus;
48-
use crate::AppState;
4949
use actix_web::body::MessageBody;
50-
use actix_web::cookie::time::format_description::well_known::Rfc3339;
5150
use actix_web::cookie::time::OffsetDateTime;
51+
use actix_web::cookie::time::format_description::well_known::Rfc3339;
5252
use actix_web::http::header::TryIntoHeaderPair;
53-
use actix_web::http::{header, StatusCode};
53+
use actix_web::http::{StatusCode, header};
5454
use actix_web::{HttpResponse, HttpResponseBuilder};
55-
use anyhow::{bail, format_err, Context as AnyhowContext};
55+
use anyhow::{Context as AnyhowContext, bail, format_err};
5656
use awc::cookie::time::Duration;
5757
use handlebars::{BlockContext, JsonValue, RenderError, Renderable};
5858
use serde::Serialize;
59-
use serde_json::{json, Value};
59+
use serde_json::{Value, json};
6060
use std::borrow::Cow;
6161
use std::convert::TryFrom;
6262
use std::fmt::Write as _;
@@ -411,9 +411,9 @@ impl HeaderContext {
411411
let html_renderer =
412412
HtmlRenderContext::new(self.app_state, self.request_context, self.writer, data)
413413
.await
414-
.with_context(|| {
415-
"Failed to create a render context from the header context."
416-
})?;
414+
.with_context(
415+
|| "Failed to create a render context from the header context.",
416+
)?;
417417
AnyRenderBodyContext::Html(html_renderer)
418418
}
419419
};
@@ -788,7 +788,9 @@ impl<W: std::io::Write> HtmlRenderContext<W> {
788788
data: &JsonValue,
789789
) -> anyhow::Result<()> {
790790
if Self::is_shell_component(component_name) {
791-
bail!("There cannot be more than a single shell per page. You are trying to open the {component_name} component, but a shell component is already opened for the current page. You can fix this by removing the extra shell component, or by moving this component to the top of the SQL file, before any other component that displays data.");
791+
bail!(
792+
"There cannot be more than a single shell per page. You are trying to open the {component_name} component, but a shell component is already opened for the current page. You can fix this by removing the extra shell component, or by moving this component to the top of the SQL file, before any other component that displays data."
793+
);
792794
}
793795

794796
if component_name == "log" {
@@ -802,10 +804,12 @@ impl<W: std::io::Write> HtmlRenderContext<W> {
802804
match self.open_component_with_data(component_name, &data).await {
803805
Ok(_) => Ok(()),
804806
Err(err) => match HeaderComponent::try_from(component_name) {
805-
Ok(_) => bail!("The {component_name} component cannot be used after data has already been sent to the client's browser. \n\
807+
Ok(_) => bail!(
808+
"The {component_name} component cannot be used after data has already been sent to the client's browser. \n\
806809
This component must be used before any other component. \n\
807810
To fix this, either move the call to the '{component_name}' component to the top of the SQL file, \n\
808-
or create a new SQL file where '{component_name}' is the first component."),
811+
or create a new SQL file where '{component_name}' is the first component."
812+
),
809813
Err(()) => Err(err),
810814
},
811815
}
@@ -1124,7 +1128,9 @@ impl SplitTemplateRenderer {
11241128
local_vars.put("row_index", self.row_index.into());
11251129
local_vars.put("component_index", self.component_index.into());
11261130
local_vars.put("csp_nonce", self.nonce.into());
1127-
log::trace!("Rendering the after_list template with the following local variables: {local_vars:?}");
1131+
log::trace!(
1132+
"Rendering the after_list template with the following local variables: {local_vars:?}"
1133+
);
11281134
*render_context
11291135
.block_mut()
11301136
.expect("ctx created without block")

0 commit comments

Comments
 (0)