Skip to content

Commit

Permalink
style: simplify statements for readability (#341)
Browse files Browse the repository at this point in the history
* style: simplify statements for readability

* refactor: replace `format` with bind in sqlx query

* update version in Cargo.toml from 0.29.2 to 0.29.3
  • Loading branch information
hamirmahal authored Nov 13, 2024
1 parent 5eab983 commit 11488be
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pgmq-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "0.29.2"
version = "0.29.3"
edition = "2021"
authors = ["Tembo.io"]
description = "A distributed message queue for Rust applications, on Postgres."
Expand Down
6 changes: 3 additions & 3 deletions pgmq-rs/examples/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main() {
.send_with_cxn(&example_queue, &msg, &mut *tx)
.await
.expect("failed to send message");
println!("message sent. id: {}, msg: {:?}", sent, msg);
println!("message sent. id: {sent}, msg: {msg:?}");

// get row count from a new connection (not the transaction)
let rows = sqlx::query("SELECT queue_length FROM pgmq.metrics($1)")
Expand All @@ -52,7 +52,7 @@ async fn main() {
.get::<i64, usize>(0);
// queue empty because transaction not committed
assert_eq!(rows, 0);
println!("queue length: {}", rows);
println!("queue length: {rows}");

// reading from queue returns no messages
let received: Option<Message<MyMessage>> = queue
Expand All @@ -73,7 +73,7 @@ async fn main() {
.get::<i64, usize>(0);
// queue empty because transaction not committed
assert_eq!(rows, 1);
println!("queue length: {}", rows);
println!("queue length: {rows}");

// reading from queue returns no messages
let received: Message<MyMessage> = queue
Expand Down
10 changes: 5 additions & 5 deletions pgmq-rs/src/pg_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl PGMQueueExt {
let queue_table = format!("pgmq.{QUEUE_PREFIX}_{queue_name}");
// we need to check whether the queue exists first
// pg_partman create operations are currently unable to be idempotent
let exists_stmt = format!(
"SELECT EXISTS(SELECT * from part_config where parent_table = '{queue_table}');",
queue_table = queue_table
);
let exists = sqlx::query_scalar(&exists_stmt).fetch_one(executor).await?;
let exists_stmt = "SELECT EXISTS(SELECT * from part_config where parent_table = $1);";
let exists = sqlx::query_scalar(exists_stmt)
.bind(queue_table)
.fetch_one(executor)
.await?;
if exists {
info!("queue: {} already exists", queue_name);
Ok(false)
Expand Down
14 changes: 7 additions & 7 deletions pgmq-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn init_queue(qname: &str) -> pgmq::PGMQueue {
let random_sleep_ms = rand::thread_rng().gen_range(0..1000);
tokio::time::sleep(std::time::Duration::from_millis(random_sleep_ms)).await;
let q_success = queue.create(qname).await;
println!("q_success: {:?}", q_success);
println!("q_success: {q_success:?}");
assert!(q_success.is_ok());
queue
}
Expand Down Expand Up @@ -654,11 +654,11 @@ async fn test_database_error_modes() {
// got the url parsing error error. good.
} else {
// got some other error. bad.
panic!("expected a url parsing error, got {:?}", e);
panic!("expected a url parsing error, got {e:?}");
}
}
// didn't get an error. bad.
_ => panic!("expected a url parsing error, got {:?}", read_msg),
_ => panic!("expected a url parsing error, got {read_msg:?}"),
}

// connect to a postgres instance that doesn't exist should error
Expand All @@ -670,11 +670,11 @@ async fn test_database_error_modes() {
// got the db error. good.
} else {
// got some other error. bad.
panic!("expected a db error, got {:?}", e);
panic!("expected a db error, got {e:?}");
}
}
// didn't get an error. bad.
_ => panic!("expected a db error, got {:?}", read_msg),
_ => panic!("expected a db error, got {read_msg:?}"),
}
}

Expand Down Expand Up @@ -712,11 +712,11 @@ async fn test_parsing_error_modes() {
// got the parsing error. good.
} else {
// got some other error. bad.
panic!("expected a parse error, got {:?}", e);
panic!("expected a parse error, got {e:?}");
}
}
// didn't get an error. bad.
_ => panic!("expected a parse error, got {:?}", read_msg),
_ => panic!("expected a parse error, got {read_msg:?}"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pgmq-rs/tests/pg_ext_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn replace_db_string(s: &str, replacement: &str) -> String {
match s.rfind('/') {
Some(pos) => {
let prefix = &s[0..pos];
format!("{}{}", prefix, replacement)
format!("{prefix}{replacement}")
}
None => s.to_string(),
}
Expand All @@ -36,7 +36,7 @@ async fn init_queue_ext(qname: &str) -> pgmq::PGMQueueExt {
let _ = queue.drop_queue(qname).await;
// CREATE QUEUE
let q_success = queue.create(qname).await;
println!("q_success: {:?}", q_success);
println!("q_success: {q_success:?}");
assert!(q_success.is_ok());
queue
}
Expand Down

0 comments on commit 11488be

Please sign in to comment.