Skip to content

Commit

Permalink
adjust new_with_pool to return PGMQueue directly (#217)
Browse files Browse the repository at this point in the history
* adjust new_with_pool to return PGMQueue directly

* fmt

* prepare release 0.27.0
  • Loading branch information
gruebel authored May 21, 2024
1 parent b530b7a commit 2702787
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 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.26.1"
version = "0.27.0"
edition = "2021"
authors = ["Tembo.io"]
description = "A distributed message queue for Rust applications, on Postgres."
Expand Down
10 changes: 5 additions & 5 deletions pgmq-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,21 @@ pub struct PGMQueue {
}

impl PGMQueue {
pub async fn new(url: String) -> Result<PGMQueue, PgmqError> {
pub async fn new(url: String) -> Result<Self, PgmqError> {
let con = util::connect(&url, 5).await?;
Ok(PGMQueue {
Ok(Self {
url,
connection: con,
})
}

/// BYOP - bring your own pool
/// initialize a PGMQ connection with your own SQLx Postgres connection pool
pub async fn new_with_pool(pool: Pool<Postgres>) -> Result<PGMQueue, PgmqError> {
Ok(PGMQueue {
pub async fn new_with_pool(pool: Pool<Postgres>) -> Self {
Self {
url: "".to_owned(),
connection: pool,
})
}
}

/// Create a queue. This sets up the queue's tables, indexes, and metadata.
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 @@ -26,20 +26,20 @@ pub struct PGMQueueMeta {
}
impl PGMQueueExt {
/// Initialize a connection to PGMQ/Postgres
pub async fn new(url: String, max_connections: u32) -> Result<PGMQueueExt, PgmqError> {
Ok(PGMQueueExt {
pub async fn new(url: String, max_connections: u32) -> Result<Self, PgmqError> {
Ok(Self {
connection: connect(&url, max_connections).await?,
url,
})
}

/// BYOP - bring your own pool
/// initialize a PGMQ connection with your own SQLx Postgres connection pool
pub async fn new_with_pool(pool: Pool<Postgres>) -> Result<PGMQueueExt, PgmqError> {
Ok(PGMQueueExt {
pub async fn new_with_pool(pool: Pool<Postgres>) -> Self {
Self {
url: "".to_owned(),
connection: pool,
})
}
}

pub async fn init(&self) -> Result<bool, PgmqError> {
Expand Down
4 changes: 1 addition & 3 deletions pgmq-rs/tests/pg_ext_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ async fn test_byop() {
let _queue = init_queue_ext(&test_queue).await;
let pool = _queue.connection;

let queue = pgmq::PGMQueueExt::new_with_pool(pool)
.await
.expect("failed to connect to postgres");
let queue = pgmq::PGMQueueExt::new_with_pool(pool).await;

let init = queue.init().await.expect("failed to create extension");
assert!(init, "failed to create extension");
Expand Down

0 comments on commit 2702787

Please sign in to comment.