Simplify query! string literals

This commit is contained in:
Joscha 2024-05-13 16:14:27 +02:00
parent 7d80ba4a6b
commit 7a6984aedc
36 changed files with 312 additions and 312 deletions

View file

@ -91,23 +91,23 @@ async fn insert_new_commits(
let message = commit.message_raw()?.to_string();
sqlx::query!(
"\
INSERT OR IGNORE INTO commits ( \
hash, \
author, \
author_date, \
committer, \
committer_date, \
message \
) \
VALUES (?, ?, ?, ?, ?, ?) \
"
INSERT OR IGNORE INTO commits (
hash,
author,
author_date,
committer,
committer_date,
message
)
VALUES (?, ?, ?, ?, ?, ?)
",
hash,
author,
author_date,
committer,
committer_date,
message
message,
)
.execute(&mut *conn)
.await?;
@ -182,13 +182,13 @@ async fn update_refs(conn: &mut SqliteConnection, refs: Vec<Reference>) -> someh
let hash = hash.to_string();
sqlx::query!(
"\
INSERT INTO refs (name, hash) VALUES (?, ?) \
ON CONFLICT (name) DO UPDATE \
SET hash = excluded.hash \
"
INSERT INTO refs (name, hash) VALUES (?, ?)
ON CONFLICT (name) DO UPDATE
SET hash = excluded.hash
",
name,
hash
hash,
)
.execute(&mut *conn)
.await?;
@ -210,28 +210,28 @@ async fn track_main_branch(conn: &mut SqliteConnection, repo: &Repository) -> so
async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> somehow::Result<()> {
sqlx::query!(
"\
WITH RECURSIVE \
tracked (hash) AS ( \
SELECT hash FROM refs WHERE tracked \
UNION \
SELECT parent FROM commit_edges \
JOIN tracked ON hash = child \
), \
reachable (hash) AS ( \
SELECT hash FROM refs \
UNION \
SELECT hash FROM tracked \
UNION \
SELECT parent FROM commit_edges \
JOIN reachable ON hash = child \
) \
UPDATE commits \
SET reachable = CASE \
WHEN hash IN tracked THEN ? \
WHEN hash IN reachable THEN ? \
ELSE ? \
END \
"
WITH RECURSIVE
tracked (hash) AS (
SELECT hash FROM refs WHERE tracked
UNION
SELECT parent FROM commit_edges
JOIN tracked ON hash = child
),
reachable (hash) AS (
SELECT hash FROM refs
UNION
SELECT hash FROM tracked
UNION
SELECT parent FROM commit_edges
JOIN reachable ON hash = child
)
UPDATE commits
SET reachable = CASE
WHEN hash IN tracked THEN ?
WHEN hash IN reachable THEN ?
ELSE ?
END
",
Reachable::FromTrackedRef,
Reachable::FromAnyRef,

View file

@ -36,10 +36,10 @@ pub async fn post_admin_queue_add(
) -> somehow::Result<impl IntoResponse> {
let date = OffsetDateTime::now_utc();
sqlx::query!(
"\
INSERT INTO queue (hash, date, priority) VALUES (?, ?, ?) \
ON CONFLICT (hash) DO UPDATE \
SET priority = excluded.priority WHERE priority < excluded.priority \
"
INSERT INTO queue (hash, date, priority) VALUES (?, ?, ?)
ON CONFLICT (hash) DO UPDATE
SET priority = excluded.priority WHERE priority < excluded.priority
",
form.hash,
date,
@ -71,14 +71,14 @@ pub async fn post_admin_queue_add_batch(
) -> somehow::Result<impl IntoResponse> {
let date = OffsetDateTime::now_utc();
let added = sqlx::query!(
"\
INSERT OR IGNORE INTO queue (hash, date, priority) \
SELECT hash, ?, ? \
FROM commits \
LEFT JOIN runs USING (hash) \
WHERE reachable = ? AND id IS NULL \
ORDER BY unixepoch(committer_date) DESC \
LIMIT ? \
"
INSERT OR IGNORE INTO queue (hash, date, priority)
SELECT hash, ?, ?
FROM commits
LEFT JOIN runs USING (hash)
WHERE reachable = ? AND id IS NULL
ORDER BY unixepoch(committer_date) DESC
LIMIT ?
",
date,
form.priority,
@ -132,7 +132,7 @@ pub async fn post_admin_queue_increase(
) -> somehow::Result<impl IntoResponse> {
sqlx::query!(
"UPDATE queue SET priority = priority + 1 WHERE hash = ?",
form.hash
form.hash,
)
.execute(&db)
.await?;
@ -155,7 +155,7 @@ pub async fn post_admin_queue_decrease(
) -> somehow::Result<impl IntoResponse> {
sqlx::query!(
"UPDATE queue SET priority = priority - 1 WHERE hash = ?",
form.hash
form.hash,
)
.execute(&db)
.await?;

View file

@ -45,18 +45,18 @@ async fn save_work(
let end = run.end.map(|t| t.0).unwrap_or_else(OffsetDateTime::now_utc);
sqlx::query!(
"\
INSERT INTO runs ( \
id, \
hash, \
bench_method, \
worker_name, \
worker_info, \
start, \
end, \
exit_code \
) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?) \
"
INSERT INTO runs (
id,
hash,
bench_method,
worker_name,
worker_info,
start,
end,
exit_code
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
",
run.id,
run.hash,
@ -78,14 +78,14 @@ async fn save_work(
for (metric, measurement) in run.measurements {
sqlx::query!(
"\
INSERT INTO run_measurements ( \
id, \
metric, \
value, \
unit \
) \
VALUES (?, ?, ?, ?) \
"
INSERT INTO run_measurements (
id,
metric,
value,
unit
)
VALUES (?, ?, ?, ?)
",
run.id,
metric,
@ -100,14 +100,14 @@ async fn save_work(
// Hopefully we won't need more than 4294967296 lines per run :P
let line = line as u32;
sqlx::query!(
"\
INSERT INTO run_output ( \
id, \
line, \
source, \
text \
) \
VALUES (?, ?, ?, ?) \
"
INSERT INTO run_output (
id,
line,
source,
text
)
VALUES (?, ?, ?, ?)
",
run.id,
line,

View file

@ -28,18 +28,18 @@ pub async fn get_commit_by_hash(
State(db): State<SqlitePool>,
) -> somehow::Result<Response> {
let Some(commit) = sqlx::query!(
"\
SELECT \
hash, \
author, \
author_date AS \"author_date: time::OffsetDateTime\", \
committer, \
committer_date AS \"committer_date: time::OffsetDateTime\", \
message, \
reachable AS \"reachable: Reachable\" \
FROM commits \
WHERE hash = ? \
",
r#"
SELECT
hash,
author,
author_date AS "author_date: time::OffsetDateTime",
committer,
committer_date AS "committer_date: time::OffsetDateTime",
message,
reachable AS "reachable: Reachable"
FROM commits
WHERE hash = ?
"#,
path.hash,
)
.fetch_optional(&db)
@ -49,16 +49,16 @@ pub async fn get_commit_by_hash(
};
let parents = sqlx::query!(
"\
SELECT \
hash, \
message, \
reachable AS \"reachable: Reachable\" \
FROM commits \
JOIN commit_edges ON hash = parent \
WHERE child = ? \
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
",
r#"
SELECT
hash,
message,
reachable AS "reachable: Reachable"
FROM commits
JOIN commit_edges ON hash = parent
WHERE child = ?
ORDER BY reachable DESC, unixepoch(committer_date) ASC
"#,
path.hash,
)
.fetch(&db)
@ -67,16 +67,16 @@ pub async fn get_commit_by_hash(
.await?;
let children = sqlx::query!(
"\
SELECT \
hash, \
message, \
reachable AS \"reachable: Reachable\" \
FROM commits \
JOIN commit_edges ON hash = child \
WHERE parent = ? \
ORDER BY reachable DESC, unixepoch(committer_date) ASC \
",
r#"
SELECT
hash,
message,
reachable AS "reachable: Reachable"
FROM commits
JOIN commit_edges ON hash = child
WHERE parent = ?
ORDER BY reachable DESC, unixepoch(committer_date) ASC
"#,
path.hash,
)
.fetch(&db)
@ -85,13 +85,13 @@ pub async fn get_commit_by_hash(
.await?;
let runs = sqlx::query!(
"\
SELECT \
id, \
start AS \"start: time::OffsetDateTime\" \
FROM runs WHERE hash = ? \
",
path.hash
r#"
SELECT
id,
start AS "start: time::OffsetDateTime"
FROM runs WHERE hash = ?
"#,
path.hash,
)
.fetch(&db)
.map_ok(|r| components::link_run_date(config, r.id, r.start))

View file

@ -93,16 +93,16 @@ pub async fn get_graph_commits(
// Fetch main commit info
let mut rows = sqlx::query!(
"\
SELECT \
hash, \
author, \
message, \
committer_date AS \"committer_date: OffsetDateTime\" \
FROM commits \
WHERE reachable = ? \
ORDER BY hash ASC \
",
r#"
SELECT
hash,
author,
message,
committer_date AS "committer_date: OffsetDateTime"
FROM commits
WHERE reachable = ?
ORDER BY hash ASC
"#,
Reachable::FromTrackedRef,
)
.fetch(&mut *conn);
@ -124,12 +124,12 @@ pub async fn get_graph_commits(
// Fetch parent info
let mut rows = sqlx::query!(
"\
SELECT child, parent \
FROM commit_edges \
JOIN commits ON hash = child \
WHERE reachable = ? \
ORDER BY hash ASC \
"
SELECT child, parent
FROM commit_edges
JOIN commits ON hash = child
WHERE reachable = ?
ORDER BY hash ASC
",
Reachable::FromTrackedRef,
)

View file

@ -27,17 +27,17 @@ pub async fn get_index(
State(db): State<SqlitePool>,
) -> somehow::Result<impl IntoResponse> {
let refs = sqlx::query!(
"\
SELECT \
name, \
hash, \
message, \
reachable AS \"reachable: Reachable\", \
tracked \
FROM refs \
JOIN commits USING (hash) \
ORDER BY name ASC \
"
r#"
SELECT
name,
hash,
message,
reachable AS "reachable: Reachable",
tracked
FROM refs
JOIN commits USING (hash)
ORDER BY name ASC
"#
)
.fetch(&db)
.map_ok(|r| Ref {

View file

@ -117,17 +117,17 @@ async fn get_queue_data(
}
let mut tasks = sqlx::query!(
"\
SELECT \
hash, \
message, \
reachable AS \"reachable: Reachable\", \
date AS \"date: time::OffsetDateTime\", \
priority \
FROM queue \
JOIN commits USING (hash) \
ORDER BY priority DESC, unixepoch(date) DESC, hash ASC \
"
r#"
SELECT
hash,
message,
reachable AS "reachable: Reachable",
date AS "date: time::OffsetDateTime",
priority
FROM queue
JOIN commits USING (hash)
ORDER BY priority DESC, unixepoch(date) DESC, hash ASC
"#
)
.fetch(db)
.map_ok(|r| Task {
@ -276,15 +276,15 @@ pub async fn get_queue_delete(
State(db): State<SqlitePool>,
) -> somehow::Result<Response> {
let Some(r) = sqlx::query!(
"\
SELECT \
hash, \
message, \
reachable AS \"reachable: Reachable\" \
FROM commits \
JOIN queue USING (hash) \
WHERE hash = ? \
",
r#"
SELECT
hash,
message,
reachable AS "reachable: Reachable"
FROM commits
JOIN queue USING (hash)
WHERE hash = ?
"#,
path.hash,
)
.fetch_optional(&db)

View file

@ -34,20 +34,20 @@ async fn from_finished_run(
db: &SqlitePool,
) -> somehow::Result<Option<Markup>> {
let Some(run) = sqlx::query!(
"\
SELECT \
id, \
hash, \
bench_method, \
start AS \"start: time::OffsetDateTime\", \
end AS \"end: time::OffsetDateTime\", \
exit_code, \
message, \
reachable AS \"reachable: Reachable\" \
FROM runs \
JOIN commits USING (hash) \
WHERE id = ? \
",
r#"
SELECT
id,
hash,
bench_method,
start AS "start: time::OffsetDateTime",
end AS "end: time::OffsetDateTime",
exit_code,
message,
reachable AS "reachable: Reachable"
FROM runs
JOIN commits USING (hash)
WHERE id = ?
"#,
id,
)
.fetch_optional(db)
@ -57,14 +57,14 @@ async fn from_finished_run(
};
let measurements = sqlx::query!(
"\
SELECT \
metric, \
value, \
unit \
FROM run_measurements \
WHERE id = ? \
ORDER BY metric ASC \
"
SELECT
metric,
value,
unit
FROM run_measurements
WHERE id = ?
ORDER BY metric ASC
",
id,
)
@ -78,10 +78,10 @@ async fn from_finished_run(
.await?;
let output = sqlx::query!(
"\
SELECT source, text FROM run_output \
WHERE id = ? \
ORDER BY line ASC \
"
SELECT source, text FROM run_output
WHERE id = ?
ORDER BY line ASC
",
id,
)